Skip to content

Commit

Permalink
Merge pull request #7 from TonimatasMCDEV/1.19/fixes
Browse files Browse the repository at this point in the history
Final fixes for Coal Crusher and Coal Combiner
  • Loading branch information
TonimatasDEV authored Jul 16, 2022
2 parents c32e623 + c90b601 commit fd22efd
Show file tree
Hide file tree
Showing 46 changed files with 204 additions and 387 deletions.
17 changes: 1 addition & 16 deletions src/main/java/net/tonimatasmc/krystalcraft/KrystalCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import net.tonimatasmc.krystalcraft.screen.CoalCrusherScreen;
import net.tonimatasmc.krystalcraft.screen.GemCuttingStationScreen;
import net.tonimatasmc.krystalcraft.screen.ModMenuTypes;
import net.tonimatasmc.krystalcraft.world.biomemods.ModBiomeModifiers;
import net.tonimatasmc.krystalcraft.world.feature.ModPlacedFeatures;

@Mod(KrystalCraft.MOD_ID)
public class KrystalCraft {
Expand All @@ -41,7 +39,7 @@ public KrystalCraft() {
ModEnchantments.register(eventBus);

//ModBiomeModifiers.register(eventBus);
// ModPlacedFeatures.register(eventBus);
//ModPlacedFeatures.register(eventBus);

eventBus.addListener(this::clientSetup);

Expand All @@ -56,17 +54,4 @@ private void clientSetup(final FMLClientSetupEvent event) {
MenuScreens.register(ModMenuTypes.COAL_CRUSHER_MENU.get(), CoalCrusherScreen::new);
MenuScreens.register(ModMenuTypes.COAL_COMBINER_MENU.get(), CoalCombinerScreen::new);
}

@SuppressWarnings("unused")
@Mod.EventBusSubscriber(modid = KrystalCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public static class Client {
private Client() {

}

private void doClientStuff(final FMLClientSetupEvent event) {
event.enqueueWork(() -> {
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ private static <T extends Block> RegistryObject<T> registerBlock(String name, Su
}

private static <T extends Block> RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block, String tooltipKey) {
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(),
new Item.Properties().tab(KrystalCraftTab.KRYSTALCRAFT)) {
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(), new Item.Properties().tab(KrystalCraftTab.KRYSTALCRAFT)) {

@Override
public void appendHoverText(@NotNull ItemStack pStack, @Nullable Level pLevel, @NotNull List<Component> pTooltip, @NotNull TooltipFlag pFlag) {
pTooltip.add(Component.translatable(tooltipKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ public CoalCombinerBlock(Properties properties) {
super(properties);
}

private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 18, 16);

@Override
public @Nonnull VoxelShape getShape(@Nullable BlockState pState, @Nullable BlockGetter pLevel, @Nullable BlockPos pPos, @Nullable CollisionContext pContext) {
return SHAPE;
return Block.box(0, 0, 0, 16, 18, 16);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ public CoalCrusherBlock(Properties properties) {
super(properties);
}

private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 18, 16);

@Override
@Nonnull
public VoxelShape getShape(@Nullable BlockState pState, @Nullable BlockGetter pLevel, @Nullable BlockPos pPos, @Nullable CollisionContext pContext) {
return SHAPE;
return Block.box(0, 0, 0, 16, 18, 16);
}

@Override
Expand Down Expand Up @@ -75,10 +73,12 @@ public RenderShape getRenderShape(@Nullable BlockState pState) {
public void onRemove(BlockState pState, @Nullable Level pLevel, @Nullable BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
if (pState.getBlock() != pNewState.getBlock()) {
BlockEntity blockEntity = Objects.requireNonNull(pLevel).getBlockEntity(Objects.requireNonNull(pPos));

if (blockEntity instanceof CoalCrusherBlockEntity) {
((CoalCrusherBlockEntity) blockEntity).drops();
}
}

super.onRemove(pState, Objects.requireNonNull(pLevel), Objects.requireNonNull(pPos), pNewState, pIsMoving);
}

Expand All @@ -87,6 +87,7 @@ public void onRemove(BlockState pState, @Nullable Level pLevel, @Nullable BlockP
public InteractionResult use(@Nullable BlockState pState, Level pLevel, @Nullable BlockPos pPos, @Nullable Player pPlayer, @Nullable InteractionHand pHand, @Nullable BlockHitResult pHit) {
if (!pLevel.isClientSide()) {
BlockEntity entity = pLevel.getBlockEntity(Objects.requireNonNull(pPos));

if(entity instanceof CoalCrusherBlockEntity) {
NetworkHooks.openGui(((ServerPlayer) Objects.requireNonNull(pPlayer)), (CoalCrusherBlockEntity)entity, pPos);
} else {
Expand All @@ -106,7 +107,6 @@ public BlockEntity newBlockEntity(@Nullable BlockPos pPos, @Nullable BlockState
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(@Nullable Level pLevel, @Nullable BlockState pState, @Nullable BlockEntityType<T> pBlockEntityType) {
return createTickerHelper(pBlockEntityType, ModBlockEntities.COAL_CRUSHER_BLOCK_ENTITY.get(),
CoalCrusherBlockEntity::tick);
return createTickerHelper(pBlockEntityType, ModBlockEntities.COAL_CRUSHER_BLOCK_ENTITY.get(), CoalCrusherBlockEntity::tick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ public GemCuttingStationBlock(Properties properties) {
super(properties);
}

private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 8, 16);

@Override
@Nonnull
public VoxelShape getShape(@Nullable BlockState pState, @Nullable BlockGetter pLevel, @Nullable BlockPos pPos, @Nullable CollisionContext pContext) {
return SHAPE;
return Block.box(0, 0, 0, 16, 8, 16);
}

@Override
Expand Down Expand Up @@ -75,10 +73,12 @@ public RenderShape getRenderShape(@Nullable BlockState pState) {
public void onRemove(BlockState pState, @Nullable Level pLevel, @Nullable BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
if (pState.getBlock() != pNewState.getBlock()) {
BlockEntity blockEntity = Objects.requireNonNull(pLevel).getBlockEntity(Objects.requireNonNull(pPos));

if (blockEntity instanceof GemCuttingStationBlockEntity) {
((GemCuttingStationBlockEntity) blockEntity).drops();
}
}

super.onRemove(pState, Objects.requireNonNull(pLevel), Objects.requireNonNull(pPos), pNewState, pIsMoving);
}

Expand All @@ -87,6 +87,7 @@ public void onRemove(BlockState pState, @Nullable Level pLevel, @Nullable BlockP
public InteractionResult use(@Nullable BlockState pState, Level pLevel, @Nullable BlockPos pPos, @Nullable Player pPlayer, @Nullable InteractionHand pHand, @Nullable BlockHitResult pHit) {
if (!pLevel.isClientSide()) {
BlockEntity entity = pLevel.getBlockEntity(Objects.requireNonNull(pPos));

if(entity instanceof GemCuttingStationBlockEntity) {
NetworkHooks.openGui(((ServerPlayer) Objects.requireNonNull(pPlayer)), (GemCuttingStationBlockEntity)entity, pPos);
} else {
Expand All @@ -106,7 +107,6 @@ public BlockEntity newBlockEntity(@Nullable BlockPos pPos, @Nullable BlockState
@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(@Nullable Level pLevel, @Nullable BlockState pState, @Nullable BlockEntityType<T> pBlockEntityType) {
return createTickerHelper(pBlockEntityType, ModBlockEntities.GEM_CUTTING_STATION_BLOCK_ENTITY.get(),
GemCuttingStationBlockEntity::tick);
return createTickerHelper(pBlockEntityType, ModBlockEntities.GEM_CUTTING_STATION_BLOCK_ENTITY.get(), GemCuttingStationBlockEntity::tick);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
public class ModBlockEntities {
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, KrystalCraft.MOD_ID);



public static final RegistryObject<BlockEntityType<GemCuttingStationBlockEntity>> GEM_CUTTING_STATION_BLOCK_ENTITY =
BLOCK_ENTITIES.register("gem_cutting_station_block_entity", () ->
BlockEntityType.Builder.of(GemCuttingStationBlockEntity::new,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.minecraft.world.SimpleContainer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraftforge.items.ItemStackHandler;
import net.tonimatasmc.krystalcraft.item.ModItems;

Expand All @@ -11,8 +10,8 @@ public static boolean hasWaterInWaterSlot(ItemStackHandler itemStackHandler) {
return itemStackHandler.getStackInSlot(0).getItem() == ModItems.SET_WATER_BOTTLES.get();
}

public static boolean hasCoalSlot(ItemStackHandler itemStackHandler, int fuelProgress, int fuelMaxProgress) {
return itemStackHandler.getStackInSlot(2).getItem() == Items.COAL || fuelProgress <= fuelMaxProgress;
public static boolean hasToolsInToolSlot(ItemStackHandler itemStackHandler) {
return itemStackHandler.getStackInSlot(2).getItem() == ModItems.GEM_CUTTER_TOOL.get();
}

public static boolean canInsertItemIntoOutputSlot(SimpleContainer inventory, ItemStack output) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentContents;
import net.minecraft.network.chat.Style;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.Containers;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.SimpleContainer;
Expand All @@ -32,7 +29,6 @@
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

Expand All @@ -45,10 +41,10 @@ protected void onContentsChanged(int slot) {
};

private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty();

protected final ContainerData data;
private int progress = 0;
private int maxProgress = 72;
private int fuel;

public CoalCombinerBlockEntity(BlockPos pWorldPosition, BlockState pBlockState) {
super(ModBlockEntities.COAL_COMBINER_BLOCK_ENTITY.get(), pWorldPosition, pBlockState);
Expand All @@ -59,6 +55,7 @@ public int get(int index) {
switch (index) {
case 0: return CoalCombinerBlockEntity.this.progress;
case 1: return CoalCombinerBlockEntity.this.maxProgress;
case 2: return CoalCombinerBlockEntity.this.fuel;
default: return 0;
}
}
Expand All @@ -67,11 +64,12 @@ public void set(int index, int value) {
switch (index) {
case 0 -> CoalCombinerBlockEntity.this.progress = value;
case 1 -> CoalCombinerBlockEntity.this.maxProgress = value;
case 2 -> CoalCombinerBlockEntity.this.fuel = value;
}
}

public int getCount() {
return 2;
return 3;
}
};
}
Expand All @@ -93,37 +91,37 @@ public AbstractContainerMenu createMenu(int pContainerId, @Nullable Inventory pI
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @javax.annotation.Nullable Direction side) {
if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return lazyItemHandler.cast();
}return super.getCapability(cap, side);
}

return super.getCapability(cap, side);
}

@Override
public void onLoad() {
super.onLoad();

lazyItemHandler = LazyOptional.of(() -> itemHandler);
}

@Override
public void invalidateCaps() {
super.invalidateCaps();

lazyItemHandler.invalidate();
}

@Override
protected void saveAdditional(@NotNull CompoundTag tag) {
tag.put("inventory", itemHandler.serializeNBT());
tag.putInt("coal_combiner.progress", progress);

tag.putInt("coal_combiner.fuel", fuel);
super.saveAdditional(tag);
}

@Override
public void load(@Nullable CompoundTag nbt) {
super.load(Objects.requireNonNull(nbt));

itemHandler.deserializeNBT(nbt.getCompound("inventory"));
progress = nbt.getInt("coal_combiner.progress");
progress = nbt.getInt("coal_combiner.fuel");
}

public void drops() {
Expand All @@ -137,12 +135,19 @@ public void drops() {
}

public static void tick(Level pLevel, BlockPos pPos, BlockState pState, CoalCombinerBlockEntity pBlockEntity) {
if(hasRecipe(pBlockEntity)) {
if (hasRecipe(pBlockEntity)) {
pBlockEntity.progress++;
setChanged(pLevel, pPos, pState);

if(pBlockEntity.progress > pBlockEntity.maxProgress) {
craftItem(pBlockEntity);
if (pBlockEntity.progress > pBlockEntity.maxProgress) {
if (pBlockEntity.fuel > 0) {
craftItem(pBlockEntity);
} else {
if (pBlockEntity.itemHandler.getStackInSlot(2).getItem() == Items.COAL || pBlockEntity.itemHandler.getStackInSlot(2).getItem() == Items.CHARCOAL) {
pBlockEntity.itemHandler.extractItem(2, 1, false);
pBlockEntity.fuel = 8;
}
}
}
} else {
pBlockEntity.resetProgress();
Expand All @@ -151,21 +156,17 @@ public static void tick(Level pLevel, BlockPos pPos, BlockState pState, CoalComb
}

private static boolean hasRecipe(CoalCombinerBlockEntity entity) {
Level level = entity.level;
SimpleContainer inventory = new SimpleContainer(entity.itemHandler.getSlots());
Level level = entity.level;

for (int i = 0; i < entity.itemHandler.getSlots(); i++) {
inventory.setItem(i, entity.itemHandler.getStackInSlot(i));
}

Optional<CoalCombinerRecipe> match = Objects.requireNonNull(level).getRecipeManager().getRecipeFor(CoalCombinerRecipe.Type.INSTANCE, inventory, level);

return match.isPresent() && Simplify.canInsertAmountIntoOutputSlot(inventory) && Simplify.canInsertItemIntoOutputSlot(inventory, match.get().getResultItem()) && hasCoalSlot(entity);

}

private static boolean hasCoalSlot(CoalCombinerBlockEntity entity) {
return entity.itemHandler.getStackInSlot(2).getItem() == Items.COAL;
return match.isPresent() && Simplify.canInsertAmountIntoOutputSlot(inventory) && Simplify.canInsertItemIntoOutputSlot(inventory, match.get().getResultItem()) &&
Simplify.hasWaterInWaterSlot(entity.itemHandler);
}

private static void craftItem(CoalCombinerBlockEntity entity) {
Expand All @@ -181,9 +182,10 @@ private static void craftItem(CoalCombinerBlockEntity entity) {
if(match.isPresent()) {
entity.itemHandler.extractItem(0,1, false);
entity.itemHandler.extractItem(1,1, false);
entity.itemHandler.extractItem(2,1, false);

entity.itemHandler.setStackInSlot(3, new ItemStack(match.get().getResultItem().getItem(), entity.itemHandler.getStackInSlot(3).getCount() + 1));

entity.fuel = entity.fuel - 1;
entity.resetProgress();
}
}
Expand Down
Loading

0 comments on commit fd22efd

Please sign in to comment.