mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-16 04:53:12 +01:00
Drill container, container rewrites, Drill augments, minor code cleaning
This commit is contained in:
parent
8286cd448a
commit
8b8aaab4f4
10 changed files with 130 additions and 78 deletions
|
@ -7,7 +7,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraftforge.common.ToolType;
|
||||
|
||||
public class CrystalBlock extends ActuallyBlock {
|
||||
private boolean isEmpowered;
|
||||
private final boolean isEmpowered;
|
||||
|
||||
public CrystalBlock(boolean isEmpowered) {
|
||||
super(Properties.create(Material.ROCK)
|
||||
|
|
|
@ -16,7 +16,7 @@ public class CrystalFluxProvider implements ICapabilityProvider {
|
|||
private int energy;
|
||||
private int transfer;
|
||||
|
||||
private LazyOptional<IEnergyStorage> capability = LazyOptional.of(() -> new CrystalFluxStorage(stack, energy, transfer));
|
||||
private final LazyOptional<IEnergyStorage> capability = LazyOptional.of(() -> new CrystalFluxStorage(stack, energy, transfer));
|
||||
|
||||
public CrystalFluxProvider(ItemStack stack, int energy) {
|
||||
this.stack = stack;
|
||||
|
|
|
@ -11,5 +11,5 @@ public final class ActuallyContainers {
|
|||
public static final DeferredRegister<ContainerType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, ActuallyAdditions.MOD_ID);
|
||||
|
||||
public static final RegistryObject<ContainerType<DrillContainer>> DRILL_CONTAINER
|
||||
= CONTAINERS.register("drill_container", () -> IForgeContainerType.create(DrillContainer::new));
|
||||
= CONTAINERS.register("drill_container", () -> IForgeContainerType.create(DrillContainer::fromNetwork));
|
||||
}
|
||||
|
|
|
@ -1,17 +1,48 @@
|
|||
package de.ellpeck.actuallyadditions.common.container;
|
||||
|
||||
import de.ellpeck.actuallyadditions.common.items.misc.DrillAugmentItem;
|
||||
import de.ellpeck.actuallyadditions.common.items.useables.DrillItem;
|
||||
import de.ellpeck.actuallyadditions.common.utilities.ContainerHelper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
|
||||
public class DrillContainer extends InventoryContainer {
|
||||
public DrillContainer(int windowId, PlayerInventory inv, PacketBuffer data) {
|
||||
super(windowId, inv, data);
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class DrillContainer extends Container {
|
||||
private final ItemStackHandler handler;
|
||||
private final PlayerInventory inv;
|
||||
private final ItemStack stack;
|
||||
|
||||
public static DrillContainer fromNetwork(int windowId, PlayerInventory inv, PacketBuffer data) {
|
||||
// Seeing as this container only works on the main hand, this works nicely
|
||||
return new DrillContainer(windowId, inv, inv.player.getHeldItemMainhand());
|
||||
}
|
||||
|
||||
public DrillContainer(int windowId, PlayerInventory inv) {
|
||||
super(windowId, inv);
|
||||
public DrillContainer(int windowId, PlayerInventory inv, ItemStack stack) {
|
||||
super(ActuallyContainers.DRILL_CONTAINER.get(), windowId);
|
||||
|
||||
this.inv = inv;
|
||||
this.stack = stack;
|
||||
|
||||
ContainerHelper.setupPlayerInventory(new InvWrapper(inv), 0, ContainerHelper.DEFAULT_SLOTS_X, 116, this::addSlot);
|
||||
|
||||
this.handler = new ItemStackHandler(5) {
|
||||
@Override
|
||||
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
|
||||
return stack.getItem() instanceof DrillAugmentItem;
|
||||
}
|
||||
};
|
||||
|
||||
this.handler.deserializeNBT(this.stack.getOrCreateChildTag("augments"));
|
||||
|
||||
this.addContainerSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,18 +51,29 @@ public class DrillContainer extends InventoryContainer {
|
|||
return playerIn.getHeldItemMainhand().getItem() instanceof DrillItem;
|
||||
}
|
||||
|
||||
protected void addContainerSlots() {
|
||||
for (int i = 0; i < 5; i ++) {
|
||||
addSlot(new SlotItemHandler(handler, i, 44 + (i * ContainerHelper.SLOT_SPACING), 19));
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
protected void addContainerSlots(int index) {
|
||||
// addSlot(new Slot());
|
||||
public ItemStack slotClick(int slotId, int dragType, @Nonnull ClickType clickTypeIn, @Nonnull PlayerEntity player) {
|
||||
if ((clickTypeIn == ClickType.SWAP || clickTypeIn == ClickType.THROW || clickTypeIn == ClickType.PICKUP)
|
||||
&& slotId >= 0
|
||||
&& slotId <= this.inventorySlots.size()
|
||||
&& inv.getStackInSlot(slotId).getItem() instanceof DrillItem) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return super.slotClick(slotId, dragType, clickTypeIn, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSlotX() {
|
||||
return DEFAULT_SLOTS_X;
|
||||
}
|
||||
public void onContainerClosed(@Nonnull PlayerEntity playerIn) {
|
||||
super.onContainerClosed(playerIn);
|
||||
|
||||
@Override
|
||||
protected int getSlotY() {
|
||||
return 116;
|
||||
this.stack.getOrCreateTag().put("augments", this.handler.serializeNBT());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package de.ellpeck.actuallyadditions.common.container;
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
import net.minecraftforge.items.wrapper.InvWrapper;
|
||||
|
||||
public abstract class InventoryContainer extends Container {
|
||||
public static final int DEFAULT_SLOTS_X = 8;
|
||||
|
||||
protected final IItemHandler playerInventory;
|
||||
|
||||
public InventoryContainer(int windowId, PlayerInventory inv, PacketBuffer data) {
|
||||
this(windowId, inv);
|
||||
}
|
||||
|
||||
public InventoryContainer(int windowId, PlayerInventory inv) {
|
||||
super(ActuallyContainers.DRILL_CONTAINER.get(), windowId);
|
||||
this.playerInventory = new InvWrapper(inv);
|
||||
|
||||
this.setupInventory();
|
||||
}
|
||||
|
||||
private void setupInventory() {
|
||||
int index = 0, x = getSlotX(), y = getSlotY();
|
||||
|
||||
// Build the players inventory first, building from bottom to top, right to left. The (i>0) magic handles the
|
||||
// space between the hotbar inventory and the players remaining inventory.
|
||||
for (int i = 0; i < 4; i++) {
|
||||
boolean isHotbar = i < 1;
|
||||
for (int j = 0; j < 9; j++) {
|
||||
addSlot(new SlotItemHandler(playerInventory, index, x + (j * 18), isHotbar ? y : ((y - 76) + (i * 18))));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
this.addContainerSlots(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will always carry on the index after setting up the players inventory
|
||||
*/
|
||||
protected abstract void addContainerSlots(int index);
|
||||
|
||||
protected abstract int getSlotX();
|
||||
protected abstract int getSlotY();
|
||||
}
|
|
@ -2,6 +2,7 @@ package de.ellpeck.actuallyadditions.common.items;
|
|||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.common.items.misc.DrillAugmentItem;
|
||||
import de.ellpeck.actuallyadditions.common.items.useables.*;
|
||||
import de.ellpeck.actuallyadditions.common.materials.ArmorMaterials;
|
||||
import de.ellpeck.actuallyadditions.common.materials.ToolMaterials;
|
||||
|
@ -128,15 +129,15 @@ public final class ActuallyItems {
|
|||
public static final RegistryObject<Item> DRILL_RED = ITEMS.register("drill_red", DrillItem::new);
|
||||
public static final RegistryObject<Item> DRILL_WHITE = ITEMS.register("drill_white", DrillItem::new);
|
||||
public static final RegistryObject<Item> DRILL_YELLOW = ITEMS.register("drill_yellow", DrillItem::new);
|
||||
public static final RegistryObject<Item> DRILL_SPEED_AUGMENT_I = ITEMS.register("drill_speed_augment_i", basicItem());
|
||||
public static final RegistryObject<Item> DRILL_SPEED_AUGMENT_II = ITEMS.register("drill_speed_augment_ii", basicItem());
|
||||
public static final RegistryObject<Item> DRILL_SPEED_AUGMENT_III = ITEMS.register("drill_speed_augment_iii", basicItem());
|
||||
public static final RegistryObject<Item> DRILL_SILK_TOUCH_AUGMENT = ITEMS.register("drill_silk_touch_augment", basicItem());
|
||||
public static final RegistryObject<Item> DRILL_FORTUNE_AUGMENT_I = ITEMS.register("drill_fortune_augment_i", basicItem());
|
||||
public static final RegistryObject<Item> DRILL_FORTUNE_AUGMENT_II = ITEMS.register("drill_fortune_augment_ii", basicItem());
|
||||
public static final RegistryObject<Item> DRILL_MINING_AUGMENT_I = ITEMS.register("drill_mining_augment_i", basicItem());
|
||||
public static final RegistryObject<Item> DRILL_MINING_AUGMENT_II = ITEMS.register("drill_mining_augment_ii", basicItem());
|
||||
public static final RegistryObject<Item> DRILL_BLOCK_PLACING_AUGMENT = ITEMS.register("drill_block_placing_augment", basicItem());
|
||||
public static final RegistryObject<Item> DRILL_SPEED_AUGMENT_I = ITEMS.register("drill_speed_augment_i", () -> new DrillAugmentItem(DrillAugmentItem.AugmentType.SPEED_AUGMENT_I));
|
||||
public static final RegistryObject<Item> DRILL_SPEED_AUGMENT_II = ITEMS.register("drill_speed_augment_ii", () -> new DrillAugmentItem(DrillAugmentItem.AugmentType.SPEED_AUGMENT_II));
|
||||
public static final RegistryObject<Item> DRILL_SPEED_AUGMENT_III = ITEMS.register("drill_speed_augment_iii", () -> new DrillAugmentItem(DrillAugmentItem.AugmentType.SPEED_AUGMENT_III));
|
||||
public static final RegistryObject<Item> DRILL_SILK_TOUCH_AUGMENT = ITEMS.register("drill_silk_touch_augment", () -> new DrillAugmentItem(DrillAugmentItem.AugmentType.SILK_TOUCH_AUGMENT));
|
||||
public static final RegistryObject<Item> DRILL_FORTUNE_AUGMENT_I = ITEMS.register("drill_fortune_augment_i", () -> new DrillAugmentItem(DrillAugmentItem.AugmentType.FORTUNE_AUGMENT_I));
|
||||
public static final RegistryObject<Item> DRILL_FORTUNE_AUGMENT_II = ITEMS.register("drill_fortune_augment_ii", () -> new DrillAugmentItem(DrillAugmentItem.AugmentType.FORTUNE_AUGMENT_II));
|
||||
public static final RegistryObject<Item> DRILL_MINING_AUGMENT_I = ITEMS.register("drill_mining_augment_i", () -> new DrillAugmentItem(DrillAugmentItem.AugmentType.MINING_AUGMENT_I));
|
||||
public static final RegistryObject<Item> DRILL_MINING_AUGMENT_II = ITEMS.register("drill_mining_augment_ii", () -> new DrillAugmentItem(DrillAugmentItem.AugmentType.MINING_AUGMENT_II));
|
||||
public static final RegistryObject<Item> DRILL_BLOCK_PLACING_AUGMENT = ITEMS.register("drill_block_placing_augment", () -> new DrillAugmentItem(DrillAugmentItem.AugmentType.BLOCK_PLACING_AUGMENT));
|
||||
public static final RegistryObject<Item> FERTILIZER = ITEMS.register("fertilizer", basicItem());
|
||||
public static final RegistryObject<Item> CUP_WITH_COFFEE = ITEMS.register("cup_with_coffee", basicItem());
|
||||
public static final RegistryObject<Item> PHANTOM_CONNECTOR = ITEMS.register("phantom_connector", basicItem());
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package de.ellpeck.actuallyadditions.common.items.misc;
|
||||
|
||||
import de.ellpeck.actuallyadditions.common.items.ActuallyItem;
|
||||
|
||||
public class DrillAugmentItem extends ActuallyItem {
|
||||
private final AugmentType type;
|
||||
|
||||
public DrillAugmentItem(AugmentType type) {
|
||||
super(baseProps().maxStackSize(1));
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public AugmentType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public enum AugmentType {
|
||||
SPEED_AUGMENT_I,
|
||||
SPEED_AUGMENT_II,
|
||||
SPEED_AUGMENT_III,
|
||||
SILK_TOUCH_AUGMENT,
|
||||
FORTUNE_AUGMENT_I,
|
||||
FORTUNE_AUGMENT_II,
|
||||
MINING_AUGMENT_I,
|
||||
MINING_AUGMENT_II,
|
||||
BLOCK_PLACING_AUGMENT
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ import net.minecraft.util.ActionResultType;
|
|||
import net.minecraftforge.common.ToolType;
|
||||
|
||||
public class AllInOneTool extends ToolItem implements IActuallyItem {
|
||||
private IItemTier tier;
|
||||
private final IItemTier tier;
|
||||
|
||||
public AllInOneTool(IItemTier tier) {
|
||||
super(
|
||||
|
|
|
@ -29,13 +29,18 @@ public class DrillItem extends CrystalFluxItem {
|
|||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity player, Hand handIn) {
|
||||
if (player.isSneaking() && !worldIn.isRemote && handIn == Hand.MAIN_HAND) {
|
||||
ItemStack stack = player.getHeldItem(handIn);
|
||||
if (worldIn.isRemote()) {
|
||||
return ActionResult.resultPass(stack);
|
||||
}
|
||||
|
||||
if (player.isSneaking() && handIn == Hand.MAIN_HAND) {
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, new SimpleNamedContainerProvider(
|
||||
(windowId, playerInv, playerEntity) -> new DrillContainer(windowId, playerInv),
|
||||
(windowId, playerInv, playerEntity) -> new DrillContainer(windowId, playerInv, stack),
|
||||
Help.trans("gui.name.drill")
|
||||
));
|
||||
}
|
||||
|
||||
return super.onItemRightClick(worldIn, player, handIn);
|
||||
return ActionResult.resultSuccess(stack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package de.ellpeck.actuallyadditions.common.utilities;
|
||||
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.SlotItemHandler;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ContainerHelper {
|
||||
public static final int DEFAULT_SLOTS_X = 8;
|
||||
public static final int SLOT_SPACING = 18;
|
||||
|
||||
public static void setupPlayerInventory(IItemHandler handler, int index, int x, int y, Consumer<Slot> consumer) {
|
||||
// Build the players inventory first, building from bottom to top, right to left. The (i>0) magic handles the
|
||||
// space between the hotbar inventory and the players remaining inventory.
|
||||
for (int i = 0; i < 4; i++) {
|
||||
boolean isHotbar = i < 1;
|
||||
for (int j = 0; j < 9; j++) {
|
||||
consumer.accept(new SlotItemHandler(handler, index, x + (j * SLOT_SPACING), isHotbar ? y : ((y - 76) + (i * SLOT_SPACING))));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue