Skip to content

Commit

Permalink
Block polishing complete(i think)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghasto69 committed Sep 15, 2023
1 parent 3f308b3 commit 6000e0e
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.ghasto.create_so.content.polishing_wheel;

import static com.simibubi.create.content.kinetics.crusher.CrushingWheelControllerBlock.VALID;

import com.ghasto.create_so.ModBlockEntities;
import com.ghasto.create_so.ModBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.content.kinetics.base.RotatedPillarKineticBlock;
import com.simibubi.create.foundation.block.IBE;
import com.simibubi.create.foundation.utility.Iterate;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.Entity;
Expand All @@ -23,6 +20,8 @@
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

import static com.simibubi.create.content.kinetics.crusher.CrushingWheelControllerBlock.VALID;

public class PolishingWheelBlock extends RotatedPillarKineticBlock implements IBE<PolishingWheelBlockEntity>{

public PolishingWheelBlock(Properties properties) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.ghasto.create_so.content.polishing_wheel;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.jetbrains.annotations.Nullable;

import com.ghasto.create_so.ModRecipeTypes;
import com.simibubi.create.AllDamageTypes;
import com.simibubi.create.content.kinetics.belt.behaviour.DirectBeltInputBehaviour;
Expand All @@ -19,7 +12,6 @@
import com.simibubi.create.foundation.utility.NBTHelper;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.infrastructure.config.AllConfigs;

import io.github.fabricators_of_create.porting_lib.util.EnvExecutor;
import io.github.fabricators_of_create.porting_lib.util.NBTSerializer;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -47,6 +39,12 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

public class PolishingWheelControllerBlockEntity extends SmartBlockEntity implements SidedStorageBlockEntity {

Expand Down
70 changes: 51 additions & 19 deletions src/main/java/com/ghasto/create_so/mixin/SandpaperItemMixin.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
package com.ghasto.create_so.mixin;

import java.util.Arrays;
import java.util.List;

import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.ghasto.create_so.ModDamageTypes;
import com.ghasto.create_so.ModItems;
import com.ghasto.create_so.util.SandpaperUtils;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.content.equipment.sandPaper.SandPaperItem;
import com.simibubi.create.foundation.item.TooltipHelper;

import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
Expand All @@ -30,11 +20,23 @@
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.StairBlock;
import net.minecraft.world.level.block.WallBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Arrays;
import java.util.List;

@Mixin(value = SandPaperItem.class)
public class SandpaperItemMixin extends Item {
Expand Down Expand Up @@ -66,18 +68,48 @@ public void injectedUseOn(UseOnContext ctx, CallbackInfoReturnable<InteractionRe
BlockState blockLookingAt = ctx.getLevel().getBlockState(ctx.getClickedPos());
Arrays.stream(SandpaperUtils.Polishable.values()).toList().forEach(polishable -> {
if(blockLookingAt.is(polishable.block)) {
ctx.getLevel().addDestroyBlockEffect(ctx.getClickedPos(), ctx.getLevel().getBlockState(ctx.getClickedPos()));
AllSoundEvents.SANDING_LONG.play(ctx.getLevel(), ctx.getPlayer(), ctx.getClickLocation(), 1, 1);
ctx.getLevel().setBlockAndUpdate(ctx.getClickedPos(), polishable.result.defaultBlockState());
if(ctx.getItemInHand().getMaxDamage() - ctx.getItemInHand().getDamageValue() != 1) {
ctx.getItemInHand().setDamageValue(ctx.getItemInHand().getDamageValue() + polishable.durabilityUsed);
} else {
ctx.getPlayer().setItemInHand(ctx.getHand(), ItemStack.EMPTY);
}
ctx.getPlayer().swing(ctx.getHand());
setBlockAndUpdateDurability(ctx, polishable.result, polishable.durabilityUsed);
} else if(blockLookingAt.is(polishable.variantInput("slab")) && polishable.variantResult("slab") instanceof SlabBlock){
setBlockAndUpdateDurability(ctx, polishable.variantResult("slab"), polishable.durabilityUsed);
} else if(blockLookingAt.is(polishable.variantInput("stairs")) && polishable.variantResult("stairs") instanceof StairBlock){
setBlockAndUpdateDurability(ctx, polishable.variantResult("stairs"), polishable.durabilityUsed);
} else if(blockLookingAt.is(polishable.variantInput("wall")) && polishable.variantResult("wall") instanceof WallBlock){
setBlockAndUpdateDurability(ctx, polishable.variantResult("wall"), polishable.durabilityUsed);
}
});
}
public void setBlockAndUpdateDurability(UseOnContext ctx, Block block, int durabilityUsed) {
BlockState blockLookingAt = ctx.getLevel().getBlockState(ctx.getClickedPos());
ctx.getPlayer().swing(ctx.getHand());
ctx.getLevel().addDestroyBlockEffect(ctx.getClickedPos(), ctx.getLevel().getBlockState(ctx.getClickedPos()));
AllSoundEvents.SANDING_LONG.play(ctx.getLevel(), ctx.getPlayer(), ctx.getClickLocation(), 1, 1);
if(blockLookingAt.getBlock() instanceof SlabBlock) {
ctx.getLevel().setBlockAndUpdate(ctx.getClickedPos(), block.defaultBlockState().setValue(SlabBlock.TYPE, blockLookingAt.getValue(SlabBlock.TYPE))
.setValue(SlabBlock.WATERLOGGED, blockLookingAt.getValue(SlabBlock.WATERLOGGED)));
} else if (blockLookingAt.getBlock() instanceof StairBlock) {
ctx.getLevel().setBlockAndUpdate(ctx.getClickedPos(), block.defaultBlockState()
.setValue(StairBlock.FACING, blockLookingAt.getValue(StairBlock.FACING))
.setValue(StairBlock.HALF, blockLookingAt.getValue(StairBlock.HALF))
.setValue(StairBlock.SHAPE, blockLookingAt.getValue(StairBlock.SHAPE))
.setValue(StairBlock.WATERLOGGED, blockLookingAt.getValue(StairBlock.WATERLOGGED)));
} else if (blockLookingAt.getBlock() instanceof WallBlock) {
ctx.getLevel().setBlockAndUpdate(ctx.getClickedPos(), block.defaultBlockState()
.setValue(WallBlock.NORTH_WALL, blockLookingAt.getValue(WallBlock.NORTH_WALL))
.setValue(WallBlock.SOUTH_WALL, blockLookingAt.getValue(WallBlock.SOUTH_WALL))
.setValue(WallBlock.WEST_WALL, blockLookingAt.getValue(WallBlock.WEST_WALL))
.setValue(WallBlock.EAST_WALL, blockLookingAt.getValue(WallBlock.EAST_WALL))
.setValue(WallBlock.UP, blockLookingAt.getValue(WallBlock.UP))
.setValue(WallBlock.WATERLOGGED, blockLookingAt.getValue(WallBlock.WATERLOGGED)));

} else {
ctx.getLevel().setBlockAndUpdate(ctx.getClickedPos(), block.defaultBlockState());
}
if(ctx.getItemInHand().getMaxDamage() - ctx.getItemInHand().getDamageValue() != 1) {
ctx.getItemInHand().setDamageValue(ctx.getItemInHand().getDamageValue() + durabilityUsed);
} else {
ctx.getPlayer().setItemInHand(ctx.getHand(), ItemStack.EMPTY);
}
}
@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltipComponents, TooltipFlag isAdvanced) {
if(Screen.hasAltDown()){
Expand Down
67 changes: 66 additions & 1 deletion src/main/java/com/ghasto/create_so/util/SandpaperUtils.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,94 @@
package com.ghasto.create_so.util;

import com.simibubi.create.content.decoration.palettes.AllPaletteStoneTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;

public class SandpaperUtils {
public enum Polishable {
//Resource Polishing
/*ROSE_QUARTZ(AllBlocks.ROSE_QUARTZ_BLOCK.get(), null),
LAPIS(ModBlocks.UNREFINED_LAPIS_BLOCK.get(), Blocks.LAPIS_BLOCK),*/

//Vanilla Blocks
SMOOTH_STONE(Blocks.STONE, Blocks.SMOOTH_STONE),
SMOOTH_SANDSTONE(Blocks.SANDSTONE, Blocks.SMOOTH_SANDSTONE)
SMOOTH_SANDSTONE(Blocks.SANDSTONE, Blocks.SMOOTH_SANDSTONE),
SMOOTH_RED_SANDSTONE(Blocks.RED_SANDSTONE, Blocks.SMOOTH_RED_SANDSTONE),
POLISHED_DEEPSLATE(Blocks.DEEPSLATE, Blocks.POLISHED_DEEPSLATE),
SMOOTH_QUARTZ(Blocks.QUARTZ_BLOCK, Blocks.SMOOTH_QUARTZ),
POLISHED_BLACKSTONE(Blocks.BLACKSTONE, Blocks.POLISHED_BLACKSTONE),
POLISHED_BASALT(Blocks.BASALT, Blocks.POLISHED_BASALT),
POLISHED_ANDESITE(Blocks.ANDESITE, Blocks.POLISHED_ANDESITE),
POLISHED_GRANITE(Blocks.GRANITE, Blocks.POLISHED_GRANITE),
POLISHED_DIORITE(Blocks.DIORITE, Blocks.POLISHED_DIORITE),

//Create Blocks
POLISHED_CUT_GRANITE(stoneType(AllPaletteStoneTypes.GRANITE, 0), stoneType(AllPaletteStoneTypes.GRANITE, 1), "create"),
POLISHED_CUT_DIORITE(stoneType(AllPaletteStoneTypes.DIORITE, 0), stoneType(AllPaletteStoneTypes.DIORITE, 1), "create"),
POLISHED_CUT_ANDESITE(stoneType(AllPaletteStoneTypes.ANDESITE, 0), stoneType(AllPaletteStoneTypes.ANDESITE, 1), "create"),
POLISHED_CUT_CALCITE(stoneType(AllPaletteStoneTypes.CALCITE, 0), stoneType(AllPaletteStoneTypes.CALCITE, 1), "create"),
POLISHED_CUT_DRIPSTONE(stoneType(AllPaletteStoneTypes.DRIPSTONE, 0), stoneType(AllPaletteStoneTypes.DRIPSTONE, 1), "create"),
POLISHED_CUT_DEEPSLATE(stoneType(AllPaletteStoneTypes.DEEPSLATE, 0), stoneType(AllPaletteStoneTypes.DEEPSLATE, 1), "create"),
POLISHED_CUT_TUFF(stoneType(AllPaletteStoneTypes.TUFF, 0), stoneType(AllPaletteStoneTypes.TUFF, 1), "create"),
POLISHED_CUT_ASURINE(stoneType(AllPaletteStoneTypes.ASURINE, 0), stoneType(AllPaletteStoneTypes.ASURINE, 1), "create"),
POLISHED_CUT_CRIMSITE(stoneType(AllPaletteStoneTypes.CRIMSITE, 0), stoneType(AllPaletteStoneTypes.CRIMSITE, 1), "create"),
POLISHED_CUT_LIMESTONE(stoneType(AllPaletteStoneTypes.LIMESTONE, 0), stoneType(AllPaletteStoneTypes.LIMESTONE, 1), "create"),
POLISHED_CUT_OCHRUM(stoneType(AllPaletteStoneTypes.OCHRUM, 0), stoneType(AllPaletteStoneTypes.OCHRUM, 1), "create"),
POLISHED_CUT_SCORIA(stoneType(AllPaletteStoneTypes.SCORIA, 0), stoneType(AllPaletteStoneTypes.SCORIA, 1), "create"),
POLISHED_CUT_SCORCHIA(stoneType(AllPaletteStoneTypes.SCORCHIA, 0), stoneType(AllPaletteStoneTypes.SCORCHIA, 1), "create"),
POLISHED_CUT_VERIDIUM(stoneType(AllPaletteStoneTypes.VERIDIUM, 0), stoneType(AllPaletteStoneTypes.VERIDIUM, 1), "create"),

//Minecraft names things weirdly :(
DEEPSLATE_SLAB(Blocks.COBBLED_DEEPSLATE_SLAB, Blocks.POLISHED_DEEPSLATE_SLAB),
DEEPSLATE_STAIRS(Blocks.COBBLED_DEEPSLATE_STAIRS, Blocks.POLISHED_DEEPSLATE_STAIRS),
DEEPSLATE_WALL(Blocks.COBBLED_DEEPSLATE_WALL, Blocks.POLISHED_DEEPSLATE_WALL)
;
public final Block block;
public final Block result;
public final int durabilityUsed;
public final String id;

Polishable(Block polishable, Block polished) {
this.block = polishable;
this.result = polished;
this.durabilityUsed = 1;
this.id = "minecraft";
}
Polishable(Block polishable, Block polished, int durabilityConsumed) {
this.block = polishable;
this.result = polished;
this.durabilityUsed = durabilityConsumed;
this.id = "minecraft";
}
Polishable(Block polishable, Block polished, String modid) {
this.block = polishable;
this.result = polished;
this.durabilityUsed = 1;
this.id = modid;
}
Polishable(Block polishable, Block polished, int durabilityConsumed, String modid) {
this.block = polishable;
this.result = polished;
this.durabilityUsed = durabilityConsumed;
this.id = modid;
}
public Block variantResult(String variantID) {
String blockid = String.valueOf(this.result).substring(7 + id.length()).replace("}", "").replace("_" + variantID, "");
return BuiltInRegistries.BLOCK.get(
new ResourceLocation(this.id, blockid + "_" + variantID));
}
public Block variantInput(String variantID) {
String blockid = String.valueOf(this.block).substring(7 + id.length()).replace("}", "").replace("_" + variantID, "");
return BuiltInRegistries.BLOCK.get(
new ResourceLocation(this.id, blockid + "_" + variantID));
}
}

//create made their system do complicated
public static Block stoneType(AllPaletteStoneTypes stoneType, int i) {
return stoneType.getVariants().registeredBlocks.get(i).get();
}
}

0 comments on commit 6000e0e

Please sign in to comment.