Skip to content

Instantly share code, notes, and snippets.

@lilypuree
Last active July 14, 2020 15:26
Show Gist options
  • Select an option

  • Save lilypuree/ff28c9e8a0b06b5f9f49d5cc0be15cb9 to your computer and use it in GitHub Desktop.

Select an option

Save lilypuree/ff28c9e8a0b06b5f9f49d5cc0be15cb9 to your computer and use it in GitHub Desktop.
package lilypuree.forest_tree.trees.customization;
import lilypuree.forest_tree.Registration;
import lilypuree.forest_tree.util.ContainerHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.IContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.IWorldPosCallable;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.*;
import javax.annotation.Nonnull;
public class TreeDesignerContainer extends Container {
private final IWorldPosCallable usabilityTest;
private final PlayerEntity player;
public static TreeDesignerContainer getClientContainer(final int windowId, final PlayerInventory playerInventory, final PacketBuffer extraData) {
return new TreeDesignerContainer(windowId, playerInventory, extraData.readBlockPos(), new ItemStackHandler(1));
}
public static IContainerProvider getServerContainerProvider(TreeDesignerTile te, BlockPos activationPos){
return (id, playerInventory, serverPlayer) -> new TreeDesignerContainer(id, playerInventory, activationPos, te.saplingHandler);
}
private TreeDesignerContainer(final int id, final PlayerInventory playerInventory, BlockPos pos, IItemHandler itemHandler) {
super(Registration.TREE_DESIGNER_CONTAINER.get(), id);
this.player = playerInventory.player;
this.usabilityTest = IWorldPosCallable.of(this.player.world, pos);
addSlot(new SlotItemHandler(itemHandler, 0, 20, 40));
// ContainerHelper.addPlayerInventoryToContainer(this, playerInventory);
}
@Nonnull
@Override
public ItemStack transferStackInSlot(PlayerEntity player, int index) {
return ContainerHelper.transferStackInSlot(this, player, index);
}
@Override
public boolean canInteractWith(PlayerEntity player) {
return isWithinUsableDistance(this.usabilityTest, player, Registration.TREE_DESIGNER_BLOCK.get());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment