Skip to content

Commit

Permalink
Merge pull request #55 from GrowthcraftCE/45-roaster-inputoutput-not-…
Browse files Browse the repository at this point in the history
…configured-properly

45 roaster inputoutput not configured properly
  • Loading branch information
Alatyami authored Oct 23, 2023
2 parents d10265c + d5b44fa commit 35244c5
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 26 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ repositories {
dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"

// JEI is required for custom recipe lookup.
compileOnly(fg.deobf("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}"))
compileOnly(fg.deobf("mezz.jei:jei-${minecraft_version}-forge-api:${jei_version}"))

// Runtime mods for testing
runtimeOnly fg.deobf("curse.maven:theoneprobe-${curseforge_theoneprobe}")
runtimeOnly fg.deobf("curse.maven:jei-${curseforge_jei}")
runtimeOnly fg.deobf("curse.maven:patchouli-${curseforge_patchouli}")
runtimeOnly fg.deobf("curse.maven:appleskin-${curseforge_appleskin}")
runtimeOnly fg.deobf("curse.maven:mekanism-${curseforge_mekanism}")

}

// This block of code expands all declared replace properties in the specified resource targets.
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ curseforge_patchouli=306770:4636277
# AppleSkin https://www.curseforge.com/minecraft/mc-mods/appleskin/files
curseforge_appleskin=248787:4770828
# ------------------------------------------------
# Mekansim, for testing pipes
curseforge_mekanism=268560:4807067
# ------------------------------------------------

20 changes: 9 additions & 11 deletions src/main/java/growthcraft/cellar/block/RoasterBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
Expand Down Expand Up @@ -131,26 +129,26 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, Block
@Override
public InteractionResult use(BlockState state, Level level, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult hitResult) {
if (!level.isClientSide) {
if (player.isCrouching()) {
if (player.getItemInHand(hand).is(GrowthcraftTags.Items.ROASTER_WRENCH)) {
// Then cycle the roaster level
RoasterBlockEntity blockEntity = (RoasterBlockEntity) level.getBlockEntity(blockPos);
// If the tick current is 0 then we are not currently processing anything.
if (blockEntity.getTickClock("current") == 0) {
blockEntity.incrementRoastingLevel();
}
} else {
// Open the GUI
try {
// Play sound
level.playSound(player, blockPos, SoundEvents.IRON_DOOR_OPEN, SoundSource.BLOCKS, 1.0F, 1.0F);
RoasterBlockEntity blockEntity = (RoasterBlockEntity) level.getBlockEntity(blockPos);
blockEntity.playSound("open");
NetworkHooks.openScreen(((ServerPlayer) player), blockEntity, blockPos);
} catch (Exception ex) {
GrowthcraftCellar.LOGGER.error(String.format("%s unable to open RoasterBlockEntity GUI at %s.", player.getDisplayName().getString(), blockPos));
GrowthcraftCellar.LOGGER.error(ex.getMessage());
GrowthcraftCellar.LOGGER.error(ex.fillInStackTrace());
}
return InteractionResult.SUCCESS;
} else if (player.getItemInHand(hand).is(GrowthcraftTags.Items.ROASTER_WRENCH)) {
// Then cycle the roaster level
RoasterBlockEntity blockEntity = (RoasterBlockEntity) level.getBlockEntity(blockPos);
// If the tick current is 0 then we are not currently processing anything.
if (blockEntity.getTickClock("current") == 0) {
blockEntity.incrementRoastingLevel();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import growthcraft.cellar.init.GrowthcraftCellarBlockEntities;
import growthcraft.cellar.recipe.RoasterRecipe;
import growthcraft.cellar.screen.container.RoasterMenu;
import growthcraft.lib.noeppi.block.entity.handler.WrappedHandler;
import growthcraft.lib.utils.BlockStateUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -13,6 +14,8 @@
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Containers;
import net.minecraft.world.MenuProvider;
Expand All @@ -39,6 +42,7 @@
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static growthcraft.cellar.block.RoasterBlock.*;
Expand All @@ -58,10 +62,50 @@ public class RoasterBlockEntity extends BlockEntity implements BlockEntityTicker
protected void onContentsChanged(int slot) {
setChanged();
}

@Override
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
return slot != 1;
}

};

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

private final Map<Direction, LazyOptional<WrappedHandler>> itemHandlerLazyDirectionalMap =
Map.of(
Direction.UP, LazyOptional.of(
() -> new WrappedHandler(itemStackHandler,
(i) -> i == 0,
(i, stack) -> this.tickClock == 0 && itemStackHandler.isItemValid(0, stack))
),
Direction.DOWN, LazyOptional.of(
() -> new WrappedHandler(itemStackHandler,
(i) -> i == 0,
(i, stack) -> this.tickClock == 0 && itemStackHandler.isItemValid(0, stack))
),
Direction.NORTH, LazyOptional.of(
() -> new WrappedHandler(itemStackHandler,
(index) -> index == 1,
(index, stack) -> false)
),
Direction.SOUTH, LazyOptional.of(
() -> new WrappedHandler(itemStackHandler,
(i) -> i == 1,
(i, s) -> false)
),
Direction.EAST, LazyOptional.of(
() -> new WrappedHandler(itemStackHandler,
(i) -> i == 1,
(index, stack) -> false)
),
Direction.WEST, LazyOptional.of(
() -> new WrappedHandler(itemStackHandler,
(index) -> index == 1,
(index, stack) -> false)
)
);

public RoasterBlockEntity(BlockPos blockPos, BlockState blockState) {
this(GrowthcraftCellarBlockEntities.ROASTER_BLOCK_ENTITY.get(), blockPos, blockState);
}
Expand Down Expand Up @@ -96,7 +140,6 @@ public int getCount() {
};
}


public boolean isHeated() {
boolean heated = BlockStateUtils.isHeated(this.level, this.getBlockPos());
// Only change the blockstate if it is different.
Expand Down Expand Up @@ -276,7 +319,24 @@ public void invalidateCaps() {
@Override
public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
if (cap == ForgeCapabilities.ITEM_HANDLER) {
return itemHandlerLazyOptional.cast();
if (side == null) {
return itemHandlerLazyOptional.cast();
}

if (itemHandlerLazyDirectionalMap.containsKey(side)) {
Direction localDir = this.getBlockState().getValue(RoasterBlock.FACING);

if (side == Direction.UP || side == Direction.DOWN) {
return itemHandlerLazyDirectionalMap.get(side).cast();
}

return switch (localDir) {
default -> itemHandlerLazyDirectionalMap.get(side.getOpposite()).cast();
case EAST -> itemHandlerLazyDirectionalMap.get(side.getClockWise()).cast();
case SOUTH -> itemHandlerLazyDirectionalMap.get(side).cast();
case WEST -> itemHandlerLazyDirectionalMap.get(side.getCounterClockWise()).cast();
};
}
}
return super.getCapability(cap, side);
}
Expand Down Expand Up @@ -320,4 +380,10 @@ public int getPercentProgress() {

return Math.round(percentage);
}

public void playSound(String sound) {
if (Objects.equals(sound, "open") && this.level != null) {
this.level.playSound(null, this.getBlockPos(), SoundEvents.IRON_DOOR_OPEN, SoundSource.BLOCKS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public int getProgressionScaled(int size) {
private static final int VANILLA_FIRST_SLOT_INDEX = 0;
private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;

private static final int TE_INVENTORY_SLOT_COUNT = 0; // must be the number of slots you have!
private static final int TE_INVENTORY_SLOT_COUNT = 3; // must be the number of slots you have!

@Override
public ItemStack quickMoveStack(Player playerIn, int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public int getProgressionScaled(int size) {
private static final int VANILLA_FIRST_SLOT_INDEX = 0;
private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;

private static final int TE_INVENTORY_SLOT_COUNT = 0; // must be the number of slots you have!
private static final int TE_INVENTORY_SLOT_COUNT = 1; // must be the number of slots you have!

@Override
public ItemStack quickMoveStack(Player playerIn, int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public int getProgressionScaled(int size) {
private static final int VANILLA_FIRST_SLOT_INDEX = 0;
private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;

private static final int TE_INVENTORY_SLOT_COUNT = 0; // must be the number of slots you have!
private static final int TE_INVENTORY_SLOT_COUNT = 1; // must be the number of slots you have!

@Override
public ItemStack quickMoveStack(Player playerIn, int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public int getProgressionScaled(int size) {
private static final int VANILLA_FIRST_SLOT_INDEX = 0;
private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;

private static final int TE_INVENTORY_SLOT_COUNT = 0; // must be the number of slots you have!
private static final int TE_INVENTORY_SLOT_COUNT = 1; // must be the number of slots you have!

@Override
public ItemStack quickMoveStack(Player playerIn, int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.items.SlotItemHandler;
import org.jetbrains.annotations.NotNull;

public class RoasterMenu extends AbstractContainerMenu {

private final RoasterBlockEntity blockEntity;
private final RoasterBlock block;
private final Level level;
private final ContainerData data;

public RoasterMenu(int containerId, Inventory inventory, FriendlyByteBuf extraData) {
this(containerId, inventory, inventory.player.level().getBlockEntity(extraData.readBlockPos()), new SimpleContainerData(2));
Expand All @@ -32,7 +32,6 @@ public RoasterMenu(int containerId, Inventory inventory, BlockEntity blockEntity
this.blockEntity = (RoasterBlockEntity) blockEntity;
this.block = (RoasterBlock) inventory.player.level().getBlockEntity(this.blockEntity.getBlockPos()).getBlockState().getBlock();
this.level = inventory.player.level();
this.data = data;

addPlayerInventory(inventory);
addPlayerHotbar(inventory);
Expand All @@ -43,7 +42,7 @@ public RoasterMenu(int containerId, Inventory inventory, BlockEntity blockEntity
this.addSlot(new SlotItemHandler(handler, 1, 106, 42));
});

addDataSlots(this.data);
addDataSlots(data);

}

Expand Down Expand Up @@ -73,12 +72,12 @@ public int getProgressionScaled(int size) {
private static final int VANILLA_FIRST_SLOT_INDEX = 0;
private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;

private static final int TE_INVENTORY_SLOT_COUNT = 0; // must be the number of slots you have!
private static final int TE_INVENTORY_SLOT_COUNT = 2; // must be the number of slots you have!

@Override
public ItemStack quickMoveStack(Player playerIn, int index) {
public @NotNull ItemStack quickMoveStack(@NotNull Player playerIn, int index) {
Slot sourceSlot = slots.get(index);
if (sourceSlot == null || !sourceSlot.hasItem()) return ItemStack.EMPTY; //EMPTY_ITEM
if (!sourceSlot.hasItem()) return ItemStack.EMPTY; //EMPTY_ITEM
ItemStack sourceStack = sourceSlot.getItem();
ItemStack copyOfSourceStack = sourceStack.copy();

Expand Down Expand Up @@ -109,7 +108,7 @@ public ItemStack quickMoveStack(Player playerIn, int index) {
}

@Override
public boolean stillValid(Player player) {
public boolean stillValid(@NotNull Player player) {
return stillValid(
ContainerLevelAccess.create(
this.level,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package growthcraft.lib.noeppi.block.entity.handler;

import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;

import javax.annotation.Nonnull;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

/*
* WrappedHandler by noeppi_noeppi
* under https://github.com/ModdingX/LibX/blob/1.19/LICENSE
*
*/
public class WrappedHandler implements IItemHandlerModifiable {
private final IItemHandlerModifiable handler;
private final Predicate<Integer> extract;
private final BiPredicate<Integer, ItemStack> insert;

public WrappedHandler(IItemHandlerModifiable handler, Predicate<Integer> extract,
BiPredicate<Integer, ItemStack> insert) {
this.handler = handler;
this.extract = extract;
this.insert = insert;
}

@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
this.handler.setStackInSlot(slot, stack);
}

@Override
public int getSlots() {
return this.handler.getSlots();
}

@Nonnull
@Override
public ItemStack getStackInSlot(int slot) {
return this.handler.getStackInSlot(slot);
}

@Nonnull
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
return this.insert.test(slot, stack) ? this.handler.insertItem(slot, stack, simulate) : stack;
}

@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
return this.extract.test(slot) ? this.handler.extractItem(slot, amount, simulate) : ItemStack.EMPTY;
}

@Override
public int getSlotLimit(int slot) {
return this.handler.getSlotLimit(slot);
}

@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
return this.insert.test(slot, stack) && this.handler.isItemValid(slot, stack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public int getProgressionScaled(int size) {
private static final int VANILLA_FIRST_SLOT_INDEX = 0;
private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;

private static final int TE_INVENTORY_SLOT_COUNT = 0; // must be the number of slots you have!
private static final int TE_INVENTORY_SLOT_COUNT = 1; // must be the number of slots you have!

@Override
public ItemStack quickMoveStack(Player playerIn, int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public BlockEntity getBlockEntity() {
private static final int VANILLA_FIRST_SLOT_INDEX = 0;
private static final int TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT;

private static final int TE_INVENTORY_SLOT_COUNT = 0; // must be the number of slots you have!
private static final int TE_INVENTORY_SLOT_COUNT = 4; // must be the number of slots you have!

@Override
public ItemStack quickMoveStack(Player playerIn, int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"type": "patchouli:text",
"text": "9.1.1 - Oct 22, 2023$(br)9.1.0 - Oct 9, 2023$(br)9.0.6 - Sep 10, 2023$(br)9.0.5 - Sep 3, 2023$(br)9.0.4 - Aug 21, 2023$(br)9.0.3 - Aug 11, 2023$(br)9.0.2 - Aug 6, 2023$(br)9.0.1 - Jul 29, 2023$(br)9.0.0 - Jul 26, 2023"
},
{
"type": "patchouli:text",
"title": "9.1.1",
"text": "$(li)Fixed shift click inventory$(li)Fixed Honey Mead recipe$(li)Fixed Brew Kettle processing$(li)Update in-game entries$(li)Fixed Roaster sided inventory$(li)Fixed Bees Wax recipe$(br2)Updated the Brew Kettle and Roaster inventory open. Shift+Empty Hand is no longer needed."
},
{
"type": "patchouli:text",
"title": "9.1.0",
Expand Down

0 comments on commit 35244c5

Please sign in to comment.