the utility class FULLY WORKS WHAT

This commit is contained in:
Ell 2021-12-02 12:31:04 +01:00
parent d8a1364bcd
commit b991f8575f
64 changed files with 385 additions and 361 deletions

View file

@ -100,7 +100,7 @@ configurations {
dependencies { dependencies {
minecraft 'net.minecraftforge:forge:1.18-38.0.8' minecraft 'net.minecraftforge:forge:1.18-38.0.8'
embed "org.jgrapht:jgrapht-core:1.5.1" embed 'org.jgrapht:jgrapht-core:1.5.1'
// TODO JEI? // TODO JEI?
/* compileOnly fg.deobf("mezz.jei:jei-1.16.2:7.3.2.25:api") /* compileOnly fg.deobf("mezz.jei:jei-1.16.2:7.3.2.25:api")

View file

@ -38,7 +38,7 @@ import de.ellpeck.prettypipes.pipe.modules.stacksize.StackSizeModuleItem;
import de.ellpeck.prettypipes.pressurizer.PressurizerBlock; import de.ellpeck.prettypipes.pressurizer.PressurizerBlock;
import de.ellpeck.prettypipes.pressurizer.PressurizerContainer; import de.ellpeck.prettypipes.pressurizer.PressurizerContainer;
import de.ellpeck.prettypipes.pressurizer.PressurizerGui; import de.ellpeck.prettypipes.pressurizer.PressurizerGui;
import de.ellpeck.prettypipes.pressurizer.PressurizerTileEntity; import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity;
import de.ellpeck.prettypipes.terminal.CraftingTerminalBlock; import de.ellpeck.prettypipes.terminal.CraftingTerminalBlock;
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity; import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
import de.ellpeck.prettypipes.terminal.ItemTerminalBlock; import de.ellpeck.prettypipes.terminal.ItemTerminalBlock;
@ -57,7 +57,7 @@ import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.INBT; import net.minecraft.nbt.INBT;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
@ -116,7 +116,7 @@ public final class Registry {
public static EntityType<PipeFrameEntity> pipeFrameEntity; public static EntityType<PipeFrameEntity> pipeFrameEntity;
public static Block pressurizerBlock; public static Block pressurizerBlock;
public static TileEntityType<PressurizerTileEntity> pressurizerTileEntity; public static TileEntityType<PressurizerBlockEntity> pressurizerTileEntity;
public static ContainerType<PressurizerContainer> pressurizerContainer; public static ContainerType<PressurizerContainer> pressurizerContainer;
public static ContainerType<ExtractionModuleContainer> extractionModuleContainer; public static ContainerType<ExtractionModuleContainer> extractionModuleContainer;
@ -169,7 +169,7 @@ public final class Registry {
pipeTileEntity = (TileEntityType<PipeTileEntity>) TileEntityType.Builder.create(PipeTileEntity::new, pipeBlock).build(null).setRegistryName("pipe"), pipeTileEntity = (TileEntityType<PipeTileEntity>) TileEntityType.Builder.create(PipeTileEntity::new, pipeBlock).build(null).setRegistryName("pipe"),
itemTerminalTileEntity = (TileEntityType<ItemTerminalTileEntity>) TileEntityType.Builder.create(ItemTerminalTileEntity::new, itemTerminalBlock).build(null).setRegistryName("item_terminal"), itemTerminalTileEntity = (TileEntityType<ItemTerminalTileEntity>) TileEntityType.Builder.create(ItemTerminalTileEntity::new, itemTerminalBlock).build(null).setRegistryName("item_terminal"),
craftingTerminalTileEntity = (TileEntityType<CraftingTerminalTileEntity>) TileEntityType.Builder.create(CraftingTerminalTileEntity::new, craftingTerminalBlock).build(null).setRegistryName("crafting_terminal"), craftingTerminalTileEntity = (TileEntityType<CraftingTerminalTileEntity>) TileEntityType.Builder.create(CraftingTerminalTileEntity::new, craftingTerminalBlock).build(null).setRegistryName("crafting_terminal"),
pressurizerTileEntity = (TileEntityType<PressurizerTileEntity>) TileEntityType.Builder.create(PressurizerTileEntity::new, pressurizerBlock).build(null).setRegistryName("pressurizer") pressurizerTileEntity = (TileEntityType<PressurizerBlockEntity>) TileEntityType.Builder.create(PressurizerBlockEntity::new, pressurizerBlock).build(null).setRegistryName("pressurizer")
); );
} }
@ -199,7 +199,7 @@ public final class Registry {
private static <T extends AbstractPipeContainer<?>> ContainerType<T> createPipeContainer(String name) { private static <T extends AbstractPipeContainer<?>> ContainerType<T> createPipeContainer(String name) {
return (ContainerType<T>) IForgeContainerType.create((windowId, inv, data) -> { return (ContainerType<T>) IForgeContainerType.create((windowId, inv, data) -> {
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, inv.player.world, data.readBlockPos()); PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, inv.player.world, data.readBlockPos());
int moduleIndex = data.readInt(); int moduleIndex = data.readInt();
ItemStack moduleStack = tile.modules.getStackInSlot(moduleIndex); ItemStack moduleStack = tile.modules.getStackInSlot(moduleIndex);
return ((IModule) moduleStack.getItem()).getContainer(moduleStack, tile, windowId, inv, inv.player, moduleIndex); return ((IModule) moduleStack.getItem()).getContainer(moduleStack, tile, windowId, inv, inv.player, moduleIndex);

View file

@ -1,30 +1,29 @@
package de.ellpeck.prettypipes; package de.ellpeck.prettypipes;
import de.ellpeck.prettypipes.items.IModule; import net.minecraft.ChatFormatting;
import de.ellpeck.prettypipes.network.PipeItem; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.block.Block; import net.minecraft.client.resources.language.I18n;
import net.minecraft.block.BlockState; import net.minecraft.core.BlockPos;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.core.Direction;
import net.minecraft.client.resources.I18n; import net.minecraft.network.chat.*;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.server.level.ServerLevel;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.inventory.ISidedInventoryProvider; import net.minecraft.world.Containers;
import net.minecraft.inventory.InventoryHelper; import net.minecraft.world.WorldlyContainer;
import net.minecraft.inventory.container.Container; import net.minecraft.world.WorldlyContainerHolder;
import net.minecraft.inventory.container.Slot; import net.minecraft.world.entity.player.Player;
import net.minecraft.item.ItemStack; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.world.inventory.Slot;
import net.minecraft.nbt.ListNBT; import net.minecraft.world.item.ItemStack;
import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.TileEntity; import net.minecraft.nbt.ListTag;
import net.minecraft.util.Direction; import net.minecraft.world.level.ChunkPos;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.Level;
import net.minecraft.util.math.ChunkPos; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.util.text.*; import net.minecraft.world.level.block.Block;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.World; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.SidedInvWrapper; import net.minecraftforge.items.wrapper.SidedInvWrapper;
@ -34,56 +33,54 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public final class Utility { public final class Utility {
public static <T extends TileEntity> T getTileEntity(Class<T> type, IBlockReader world, BlockPos pos) { public static <T extends BlockEntity> T getBlockEntity(Class<T> type, LevelAccessor world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos); var tile = world.getBlockEntity(pos);
return type.isInstance(tile) ? (T) tile : null; return type.isInstance(tile) ? (T) tile : null;
} }
public static void dropInventory(TileEntity tile, IItemHandler inventory) { public static void dropInventory(BlockEntity tile, IItemHandler inventory) {
BlockPos pos = tile.getPos(); var pos = tile.getBlockPos();
for (int i = 0; i < inventory.getSlots(); i++) { for (var i = 0; i < inventory.getSlots(); i++) {
ItemStack stack = inventory.getStackInSlot(i); var stack = inventory.getStackInSlot(i);
if (!stack.isEmpty()) if (!stack.isEmpty())
InventoryHelper.spawnItemStack(tile.getWorld(), pos.getX(), pos.getY(), pos.getZ(), stack); Containers.dropItemStack(tile.getLevel(), pos.getX(), pos.getY(), pos.getZ(), stack);
} }
} }
public static Direction getDirectionFromOffset(BlockPos pos, BlockPos other) { public static Direction getDirectionFromOffset(BlockPos pos, BlockPos other) {
BlockPos diff = pos.subtract(other); var diff = pos.subtract(other);
return Direction.getFacingFromVector(diff.getX(), diff.getY(), diff.getZ()); return Direction.fromNormal(diff.getX(), diff.getY(), diff.getZ());
} }
public static void addTooltip(String name, List<ITextComponent> tooltip) { public static void addTooltip(String name, List<MutableComponent> tooltip) {
if (Screen.hasShiftDown()) { if (Screen.hasShiftDown()) {
String[] content = I18n.format("info." + PrettyPipes.ID + "." + name).split("\n"); var content = I18n.get("info." + PrettyPipes.ID + "." + name).split("\n");
for (String s : content) for (var s : content)
tooltip.add(new StringTextComponent(s).setStyle(Style.EMPTY.setFormatting(TextFormatting.GRAY))); tooltip.add(new TextComponent(s).setStyle(Style.EMPTY.applyFormat(ChatFormatting.GRAY)));
} else { } else {
tooltip.add(new TranslationTextComponent("info." + PrettyPipes.ID + ".shift").setStyle(Style.EMPTY.setFormatting(TextFormatting.DARK_GRAY))); tooltip.add(new TranslatableComponent("info." + PrettyPipes.ID + ".shift").setStyle(Style.EMPTY.applyFormat(ChatFormatting.DARK_GRAY)));
} }
} }
public static ItemStack transferStackInSlot(Container container, IMergeItemStack merge, PlayerEntity player, int slotIndex, Function<ItemStack, Pair<Integer, Integer>> predicate) { public static ItemStack transferStackInSlot(AbstractContainerMenu container, IMergeItemStack merge, Player player, int slotIndex, Function<ItemStack, Pair<Integer, Integer>> predicate) {
int inventoryStart = (int) container.inventorySlots.stream().filter(slot -> slot.inventory != player.inventory).count(); var inventoryStart = (int) container.slots.stream().filter(slot -> slot.container != player.getInventory()).count();
int inventoryEnd = inventoryStart + 26; var inventoryEnd = inventoryStart + 26;
int hotbarStart = inventoryEnd + 1; var hotbarStart = inventoryEnd + 1;
int hotbarEnd = hotbarStart + 8; var hotbarEnd = hotbarStart + 8;
Slot slot = container.inventorySlots.get(slotIndex); var slot = container.slots.get(slotIndex);
if (slot != null && slot.getHasStack()) { if (slot != null && slot.hasItem()) {
ItemStack newStack = slot.getStack(); var newStack = slot.getItem();
ItemStack currentStack = newStack.copy(); var currentStack = newStack.copy();
if (slotIndex >= inventoryStart) { if (slotIndex >= inventoryStart) {
// shift into this container here // shift into this container here
// mergeItemStack with the slots that newStack should go into // mergeItemStack with the slots that newStack should go into
// return an empty stack if mergeItemStack fails // return an empty stack if mergeItemStack fails
Pair<Integer, Integer> slots = predicate.apply(newStack); var slots = predicate.apply(newStack);
if (slots != null) { if (slots != null) {
if (!merge.mergeItemStack(newStack, slots.getLeft(), slots.getRight(), false)) if (!merge.mergeItemStack(newStack, slots.getLeft(), slots.getRight(), false))
return ItemStack.EMPTY; return ItemStack.EMPTY;
@ -99,9 +96,9 @@ public final class Utility {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
if (newStack.isEmpty()) { if (newStack.isEmpty()) {
slot.putStack(ItemStack.EMPTY); slot.set(ItemStack.EMPTY);
} else { } else {
slot.onSlotChanged(); slot.setChanged();
} }
if (newStack.getCount() == currentStack.getCount()) if (newStack.getCount() == currentStack.getCount())
return ItemStack.EMPTY; return ItemStack.EMPTY;
@ -111,42 +108,44 @@ public final class Utility {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
public static ListNBT serializeAll(Collection<? extends INBTSerializable<CompoundNBT>> items) { public static ListTag serializeAll(Collection<? extends INBTSerializable<CompoundTag>> items) {
ListNBT list = new ListNBT(); var list = new ListTag();
for (INBTSerializable<CompoundNBT> item : items) for (INBTSerializable<CompoundTag> item : items)
list.add(item.serializeNBT()); list.add(item.serializeNBT());
return list; return list;
} }
public static void sendTileEntityToClients(TileEntity tile) { public static void sendBlockEntityToClients(BlockEntity tile) {
ServerWorld world = (ServerWorld) tile.getWorld(); var world = (ServerLevel) tile.getLevel();
Stream<ServerPlayerEntity> entities = world.getChunkProvider().chunkManager.getTrackingPlayers(new ChunkPos(tile.getPos()), false); var entities = world.getChunkSource().chunkMap.getPlayers(new ChunkPos(tile.getBlockPos()), false);
SUpdateTileEntityPacket packet = new SUpdateTileEntityPacket(tile.getPos(), -1, tile.write(new CompoundNBT())); var packet = ClientboundBlockEntityDataPacket.create(tile, t -> t.save(new CompoundTag()));
entities.forEach(e -> e.connection.sendPacket(packet)); for (var e : entities)
e.connection.send(packet);
} }
public static <T extends INBTSerializable<CompoundNBT>> List<T> deserializeAll(ListNBT list, Function<CompoundNBT, T> supplier) { public static <T extends INBTSerializable<CompoundTag>> List<T> deserializeAll(ListTag list, Function<CompoundTag, T> supplier) {
List<T> items = new ArrayList<>(); List<T> items = new ArrayList<>();
for (int i = 0; i < list.size(); i++) { for (var i = 0; i < list.size(); i++) {
T item = supplier.apply(list.getCompound(i)); var item = supplier.apply(list.getCompound(i));
if (item != null) if (item != null)
items.add(item); items.add(item);
} }
return items; return items;
} }
public static IItemHandler getBlockItemHandler(World world, BlockPos pos, Direction direction) { public static IItemHandler getBlockItemHandler(Level world, BlockPos pos, Direction direction) {
BlockState state = world.getBlockState(pos); var state = world.getBlockState(pos);
Block block = state.getBlock(); var block = state.getBlock();
if (!(block instanceof ISidedInventoryProvider)) if (!(block instanceof WorldlyContainerHolder holder))
return null; return null;
ISidedInventory inventory = ((ISidedInventoryProvider) block).createInventory(state, world, pos); var inventory = holder.getContainer(state, world, pos);
if (inventory == null) if (inventory == null)
return null; return null;
return new SidedInvWrapper(inventory, direction); return new SidedInvWrapper(inventory, direction);
} }
public interface IMergeItemStack { public interface IMergeItemStack {
boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection); boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, boolean reverseDirection);
} }
} }

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.prettypipes.compat.jei; package de.ellpeck.prettypipes.compat.jei;
import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.misc.ItemEquality;
@ -9,7 +10,7 @@ import mezz.jei.api.gui.ingredient.IGuiIngredient;
import mezz.jei.api.recipe.transfer.IRecipeTransferError; import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -50,3 +51,4 @@ public class CraftingModuleTransferHandler implements IRecipeTransferHandler<Cra
return null; return null;
} }
} }
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.prettypipes.compat.jei; package de.ellpeck.prettypipes.compat.jei;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
@ -13,7 +14,7 @@ import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Slot; import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Map; import java.util.Map;
@ -39,3 +40,4 @@ public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<C
return null; return null;
} }
} }
*/

View file

@ -1,3 +1,4 @@
/*
package de.ellpeck.prettypipes.compat.jei; package de.ellpeck.prettypipes.compat.jei;
import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.PrettyPipes;
@ -16,7 +17,7 @@ import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.renderer.Rectangle2d; import net.minecraft.client.renderer.Rectangle2d;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
@ -132,3 +133,4 @@ public class JEIPrettyPipesPlugin implements IModPlugin {
} }
} }
} }
*/

View file

@ -5,12 +5,19 @@ import de.ellpeck.prettypipes.network.NetworkLocation;
import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.network.PipeNetwork;
import de.ellpeck.prettypipes.pipe.PipeBlock; import de.ellpeck.prettypipes.pipe.PipeBlock;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.item.ItemFrameEntity; import net.minecraft.entity.item.ItemFrameEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.FilledMapItem; import net.minecraft.item.FilledMapItem;
import net.minecraft.item.ItemStack; import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.ItemFrame;
import net.minecraft.world.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.network.IPacket; import net.minecraft.network.IPacket;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
@ -21,55 +28,58 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.GameRules; import net.minecraft.world.GameRules;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.storage.MapData; import net.minecraft.world.storage.MapData;
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.fml.network.NetworkHooks;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class PipeFrameEntity extends ItemFrameEntity implements IEntityAdditionalSpawnData { public class PipeFrameEntity extends ItemFrame implements IEntityAdditionalSpawnData {
private static final DataParameter<Integer> AMOUNT = EntityDataManager.createKey(PipeFrameEntity.class, DataSerializers.VARINT); private static final EntityDataAccessor<Integer> AMOUNT = SynchedEntityData.defineId(PipeFrameEntity.class, EntityDataSerializers.INT);
public PipeFrameEntity(EntityType<PipeFrameEntity> type, World world) { public PipeFrameEntity(EntityType<PipeFrameEntity> type, Level world) {
super(type, world); super(type, world);
} }
public PipeFrameEntity(EntityType<PipeFrameEntity> type, World world, BlockPos pos, Direction dir) { public PipeFrameEntity(EntityType<PipeFrameEntity> type, Level world, BlockPos pos, Direction dir) {
this(type, world); this(type, world);
this.hangingPosition = pos; this.pos = pos;
this.updateFacingWithBoundingBox(dir); this.setDirection(dir);
} }
@Override @Override
protected void registerData() { protected void defineSynchedData() {
super.registerData(); super.defineSynchedData();
this.dataManager.register(AMOUNT, -1); this.entityData.define(AMOUNT, -1);
} }
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
if (this.world.isRemote) if (this.level.isClientSide)
return; return;
if (this.ticksExisted % 40 != 0) if (this.tickCount % 40 != 0)
return; return;
PipeNetwork network = PipeNetwork.get(this.world); PipeNetwork network = PipeNetwork.get(this.level);
BlockPos attached = getAttachedPipe(this.world, this.hangingPosition, this.facingDirection); BlockPos attached = getAttachedPipe(this.level, this.pos, this.direction);
if (attached != null) { if (attached != null) {
BlockPos node = network.getNodeFromPipe(attached); BlockPos node = network.getNodeFromPipe(attached);
if (node != null) { if (node != null) {
ItemStack stack = this.getDisplayedItem(); ItemStack stack = this.getItem();
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
List<NetworkLocation> items = network.getOrderedNetworkItems(node); List<NetworkLocation> items = network.getOrderedNetworkItems(node);
int amount = items.stream().mapToInt(i -> i.getItemAmount(this.world, stack)).sum(); int amount = items.stream().mapToInt(i -> i.getItemAmount(this.level, stack)).sum();
this.dataManager.set(AMOUNT, amount); this.entityData.set(AMOUNT, amount);
return; return;
} }
} }
} }
this.dataManager.set(AMOUNT, -1); this.entityData.set(AMOUNT, -1);
} }
@Override @Override
@ -77,9 +87,9 @@ public class PipeFrameEntity extends ItemFrameEntity implements IEntityAdditiona
return super.onValidSurface() && canPlace(this.world, this.hangingPosition, this.facingDirection); return super.onValidSurface() && canPlace(this.world, this.hangingPosition, this.facingDirection);
} }
private static BlockPos getAttachedPipe(World world, BlockPos pos, Direction direction) { private static BlockPos getAttachedPipe(Level world, BlockPos pos, Direction direction) {
for (int i = 1; i <= 2; i++) { for (int i = 1; i <= 2; i++) {
BlockPos offset = pos.offset(direction.getOpposite(), i); BlockPos offset = pos.relative(direction.getOpposite(), i);
BlockState state = world.getBlockState(offset); BlockState state = world.getBlockState(offset);
if (state.getBlock() instanceof PipeBlock) if (state.getBlock() instanceof PipeBlock)
return offset; return offset;

View file

@ -5,7 +5,7 @@ import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;

View file

@ -9,7 +9,7 @@ import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;

View file

@ -11,9 +11,9 @@ import net.minecraft.entity.item.ItemFrameEntity;
import net.minecraft.entity.item.PaintingEntity; import net.minecraft.entity.item.PaintingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.item.ItemUseContext; import net.minecraft.item.ItemUseContext;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.ActionResultType; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -42,9 +42,9 @@ public class PipeFrameItem extends Item {
World world = context.getWorld(); World world = context.getWorld();
HangingEntity hangingentity = new PipeFrameEntity(Registry.pipeFrameEntity, world, blockpos1, direction); HangingEntity hangingentity = new PipeFrameEntity(Registry.pipeFrameEntity, world, blockpos1, direction);
CompoundNBT compoundnbt = itemstack.getTag(); CompoundTag CompoundTag = itemstack.getTag();
if (compoundnbt != null) { if (CompoundTag != null) {
EntityType.applyItemNBT(world, playerentity, hangingentity, compoundnbt); EntityType.applyItemNBT(world, playerentity, hangingentity, CompoundTag);
} }
if (hangingentity.onValidSurface()) { if (hangingentity.onValidSurface()) {

View file

@ -40,7 +40,7 @@ public class WrenchItem extends Item {
BlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
if (!(state.getBlock() instanceof PipeBlock)) if (!(state.getBlock() instanceof PipeBlock))
return ActionResultType.PASS; return ActionResultType.PASS;
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, world, pos); PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, world, pos);
if (tile == null) if (tile == null)
return ActionResultType.FAIL; return ActionResultType.FAIL;
@ -49,7 +49,7 @@ public class WrenchItem extends Item {
if (tile.cover != null) { if (tile.cover != null) {
// remove the cover // remove the cover
tile.removeCover(player, context.getHand()); tile.removeCover(player, context.getHand());
Utility.sendTileEntityToClients(tile); Utility.sendBlockEntityToClients(tile);
} else { } else {
// remove the pipe // remove the pipe
PipeBlock.dropItems(world, pos, player); PipeBlock.dropItems(world, pos, player);
@ -71,7 +71,7 @@ public class WrenchItem extends Item {
BlockState cover = block.getStateForPlacement(blockContext); BlockState cover = block.getStateForPlacement(blockContext);
if (cover != null && !block.hasTileEntity(cover)) { if (cover != null && !block.hasTileEntity(cover)) {
tile.cover = cover; tile.cover = cover;
Utility.sendTileEntityToClients(tile); Utility.sendBlockEntityToClients(tile);
offhand.shrink(1); offhand.shrink(1);
world.playSound(null, pos, SoundEvents.ENTITY_ITEM_FRAME_ADD_ITEM, SoundCategory.PLAYERS, 1, 1); world.playSound(null, pos, SoundEvents.ENTITY_ITEM_FRAME_ADD_ITEM, SoundCategory.PLAYERS, 1, 1);
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.prettypipes.misc; package de.ellpeck.prettypipes.misc;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;

View file

@ -2,7 +2,7 @@ package de.ellpeck.prettypipes.misc;
import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.network.PipeNetwork;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;

View file

@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.misc;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot; import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler; import net.minecraftforge.items.SlotItemHandler;

View file

@ -1,15 +1,16 @@
package de.ellpeck.prettypipes.misc; package de.ellpeck.prettypipes.misc;
import net.minecraft.item.ItemStack; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ResourceLocation; import net.minecraft.world.item.ItemStack;
import net.minecraft.resources.ResourceLocation;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Supplier; import java.util.function.Supplier;
public class ItemEquality { public class ItemEquality {
public static final ItemEquality DAMAGE = new ItemEquality((stack, filter) -> stack.getDamage() == filter.getDamage(), false, Type.DAMAGE); public static final ItemEquality DAMAGE = new ItemEquality((stack, filter) -> stack.getDamageValue() == filter.getDamageValue(), false, Type.DAMAGE);
public static final ItemEquality NBT = new ItemEquality(ItemStack::areItemStackTagsEqual, false, Type.NBT); public static final ItemEquality NBT = new ItemEquality(ItemStack::isSameItemSameTags, false, Type.NBT);
public static final ItemEquality MOD = new ItemEquality((stack, filter) -> stack.getItem().getCreatorModId(stack).equals(filter.getItem().getCreatorModId(filter)), true, Type.MOD); public static final ItemEquality MOD = new ItemEquality((stack, filter) -> stack.getItem().getCreatorModId(stack).equals(filter.getItem().getCreatorModId(filter)), true, Type.MOD);
public final Type type; public final Type type;
@ -27,10 +28,10 @@ public class ItemEquality {
} }
public static boolean compareItems(ItemStack stack, ItemStack filter, ItemEquality... types) { public static boolean compareItems(ItemStack stack, ItemStack filter, ItemEquality... types) {
boolean equal = ItemStack.areItemsEqual(stack, filter); var equal = ItemStack.isSameIgnoreDurability(stack, filter);
if (types.length <= 0) if (types.length <= 0)
return equal; return equal;
for (ItemEquality type : types) { for (var type : types) {
if (!type.ignoreItemEquality && !equal) if (!type.ignoreItemEquality && !equal)
return false; return false;
if (!type.filter.apply(stack, filter)) if (!type.filter.apply(stack, filter))

View file

@ -1,19 +1,17 @@
package de.ellpeck.prettypipes.misc; package de.ellpeck.prettypipes.misc;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.PoseStack;
import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.PrettyPipes;
import de.ellpeck.prettypipes.packets.PacketButton; import de.ellpeck.prettypipes.packets.PacketButton;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem; import de.ellpeck.prettypipes.pipe.modules.modifier.FilterModifierModuleItem;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.gui.components.Widget;
import net.minecraft.inventory.container.Slot; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.item.ItemStack; import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.world.inventory.Slot;
import net.minecraft.util.Direction; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@ -53,17 +51,17 @@ public class ItemFilter extends ItemStackHandler {
public List<Widget> getButtons(Screen gui, int x, int y) { public List<Widget> getButtons(Screen gui, int x, int y) {
List<Widget> buttons = new ArrayList<>(); List<Widget> buttons = new ArrayList<>();
if (this.canModifyWhitelist) { if (this.canModifyWhitelist) {
Supplier<TranslationTextComponent> whitelistText = () -> new TranslationTextComponent("info." + PrettyPipes.ID + "." + (this.isWhitelist ? "whitelist" : "blacklist")); Supplier<TranslatableComponent> whitelistText = () -> new TranslatableComponent("info." + PrettyPipes.ID + "." + (this.isWhitelist ? "whitelist" : "blacklist"));
buttons.add(new Button(x, y, 70, 20, whitelistText.get(), button -> { buttons.add(new Button(x, y, 70, 20, whitelistText.get(), button -> {
PacketButton.sendAndExecute(this.pipe.getPos(), PacketButton.ButtonResult.FILTER_CHANGE, 0); PacketButton.sendAndExecute(this.pipe.getPos(), PacketButton.ButtonResult.FILTER_CHANGE, 0);
button.setMessage(whitelistText.get()); button.setMessage(whitelistText.get());
})); }));
} }
if (this.canPopulateFromInventories) { if (this.canPopulateFromInventories) {
buttons.add(new Button(x + 72, y, 70, 20, new TranslationTextComponent("info." + PrettyPipes.ID + ".populate"), button -> PacketButton.sendAndExecute(this.pipe.getPos(), PacketButton.ButtonResult.FILTER_CHANGE, 1)) { buttons.add(new Button(x + 72, y, 70, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".populate"), button -> PacketButton.sendAndExecute(this.pipe.getPos(), PacketButton.ButtonResult.FILTER_CHANGE, 1)) {
@Override @Override
public void renderToolTip(MatrixStack matrix, int x, int y) { public void renderToolTip(PoseStack matrix, int x, int y) {
gui.renderTooltip(matrix, new TranslationTextComponent("info." + PrettyPipes.ID + ".populate.description").mergeStyle(TextFormatting.GRAY), x, y); gui.renderTooltip(matrix, new TranslatableComponent("info." + PrettyPipes.ID + ".populate.description").withStyle(ChatFormatting.GRAY), x, y);
} }
}); });
} }
@ -127,15 +125,15 @@ public class ItemFilter extends ItemStackHandler {
} }
@Override @Override
public CompoundNBT serializeNBT() { public CompoundTag serializeNBT() {
CompoundNBT nbt = super.serializeNBT(); CompoundTag nbt = super.serializeNBT();
if (this.canModifyWhitelist) if (this.canModifyWhitelist)
nbt.putBoolean("whitelist", this.isWhitelist); nbt.putBoolean("whitelist", this.isWhitelist);
return nbt; return nbt;
} }
@Override @Override
public void deserializeNBT(CompoundNBT nbt) { public void deserializeNBT(CompoundTag nbt) {
super.deserializeNBT(nbt); super.deserializeNBT(nbt);
if (this.canModifyWhitelist) if (this.canModifyWhitelist)
this.isWhitelist = nbt.getBoolean("whitelist"); this.isWhitelist = nbt.getBoolean("whitelist");

View file

@ -1,6 +1,6 @@
package de.ellpeck.prettypipes.misc; package de.ellpeck.prettypipes.misc;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import java.util.Comparator; import java.util.Comparator;

View file

@ -9,8 +9,8 @@ import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.Widget;
import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextComponent; import net.minecraft.util.text.TextComponent;

View file

@ -1,24 +1,24 @@
package de.ellpeck.prettypipes.network; package de.ellpeck.prettypipes.network;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NBTUtil; import net.minecraft.nbt.ListTag;
import net.minecraft.util.math.BlockPos; import net.minecraft.nbt.NbtUtils;
import net.minecraftforge.common.util.Constants; import net.minecraft.nbt.Tag;
import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.common.util.INBTSerializable;
import org.jgrapht.graph.DefaultWeightedEdge; import org.jgrapht.graph.DefaultWeightedEdge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable<CompoundNBT> { public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable<CompoundTag> {
public final List<BlockPos> pipes = new ArrayList<>(); public final List<BlockPos> pipes = new ArrayList<>();
public NetworkEdge() { public NetworkEdge() {
} }
public NetworkEdge(CompoundNBT nbt) { public NetworkEdge(CompoundTag nbt) {
this.deserializeNBT(nbt); this.deserializeNBT(nbt);
} }
@ -31,20 +31,20 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable
} }
@Override @Override
public CompoundNBT serializeNBT() { public CompoundTag serializeNBT() {
CompoundNBT nbt = new CompoundNBT(); CompoundTag nbt = new CompoundTag();
ListNBT list = new ListNBT(); ListTag list = new ListTag();
for (BlockPos pos : this.pipes) for (BlockPos pos : this.pipes)
list.add(NBTUtil.writeBlockPos(pos)); list.add(NbtUtils.writeBlockPos(pos));
nbt.put("pipes", list); nbt.put("pipes", list);
return nbt; return nbt;
} }
@Override @Override
public void deserializeNBT(CompoundNBT nbt) { public void deserializeNBT(CompoundTag nbt) {
this.pipes.clear(); this.pipes.clear();
ListNBT list = nbt.getList("pipes", Constants.NBT.TAG_COMPOUND); ListTag list = nbt.getList("pipes", Tag.TAG_COMPOUND);
for (int i = 0; i < list.size(); i++) for (int i = 0; i < list.size(); i++)
this.pipes.add(NBTUtil.readBlockPos(list.getCompound(i))); this.pipes.add(NbtUtils.readBlockPos(list.getCompound(i)));
} }
} }

View file

@ -1,7 +1,7 @@
package de.ellpeck.prettypipes.network; package de.ellpeck.prettypipes.network;
import de.ellpeck.prettypipes.misc.EquatableItemStack; import de.ellpeck.prettypipes.misc.EquatableItemStack;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import java.util.*; import java.util.*;

View file

@ -2,8 +2,8 @@ package de.ellpeck.prettypipes.network;
import de.ellpeck.prettypipes.misc.ItemEquality; import de.ellpeck.prettypipes.misc.ItemEquality;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NBTUtil; import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -17,7 +17,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class NetworkLocation implements INBTSerializable<CompoundNBT> { public class NetworkLocation implements INBTSerializable<CompoundTag> {
public BlockPos pipePos; public BlockPos pipePos;
public Direction direction; public Direction direction;
@ -29,7 +29,7 @@ public class NetworkLocation implements INBTSerializable<CompoundNBT> {
this.direction = direction; this.direction = direction;
} }
public NetworkLocation(CompoundNBT nbt) { public NetworkLocation(CompoundTag nbt) {
this.deserializeNBT(nbt); this.deserializeNBT(nbt);
} }
@ -92,15 +92,15 @@ public class NetworkLocation implements INBTSerializable<CompoundNBT> {
} }
@Override @Override
public CompoundNBT serializeNBT() { public CompoundTag serializeNBT() {
CompoundNBT nbt = new CompoundNBT(); CompoundTag nbt = new CompoundTag();
nbt.put("pipe_pos", NBTUtil.writeBlockPos(this.pipePos)); nbt.put("pipe_pos", NBTUtil.writeBlockPos(this.pipePos));
nbt.putInt("direction", this.direction.getIndex()); nbt.putInt("direction", this.direction.getIndex());
return nbt; return nbt;
} }
@Override @Override
public void deserializeNBT(CompoundNBT nbt) { public void deserializeNBT(CompoundTag nbt) {
this.pipePos = NBTUtil.readBlockPos(nbt.getCompound("pipe_pos")); this.pipePos = NBTUtil.readBlockPos(nbt.getCompound("pipe_pos"));
this.direction = Direction.byIndex(nbt.getInt("direction")); this.direction = Direction.byIndex(nbt.getInt("direction"));
} }

View file

@ -1,14 +1,14 @@
package de.ellpeck.prettypipes.network; package de.ellpeck.prettypipes.network;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListTag;
import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.common.util.INBTSerializable;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class NetworkLock implements INBTSerializable<CompoundNBT> { public class NetworkLock implements INBTSerializable<CompoundTag> {
// identify locks by UUID since network locks can't be identified by location and locked item alone // identify locks by UUID since network locks can't be identified by location and locked item alone
// (two locks could be set for the same item and the same amount if it exists twice in the chest) // (two locks could be set for the same item and the same amount if it exists twice in the chest)
@ -21,21 +21,21 @@ public class NetworkLock implements INBTSerializable<CompoundNBT> {
this.stack = stack; this.stack = stack;
} }
public NetworkLock(CompoundNBT nbt) { public NetworkLock(CompoundTag nbt) {
this.deserializeNBT(nbt); this.deserializeNBT(nbt);
} }
@Override @Override
public CompoundNBT serializeNBT() { public CompoundTag serializeNBT() {
CompoundNBT nbt = new CompoundNBT(); CompoundTag nbt = new CompoundTag();
nbt.putUniqueId("id", this.lockId); nbt.putUniqueId("id", this.lockId);
nbt.put("location", this.location.serializeNBT()); nbt.put("location", this.location.serializeNBT());
nbt.put("stack", this.stack.write(new CompoundNBT())); nbt.put("stack", this.stack.write(new CompoundTag()));
return nbt; return nbt;
} }
@Override @Override
public void deserializeNBT(CompoundNBT nbt) { public void deserializeNBT(CompoundTag nbt) {
this.lockId = nbt.getUniqueId("id"); this.lockId = nbt.getUniqueId("id");
this.location = new NetworkLocation(nbt.getCompound("location")); this.location = new NetworkLocation(nbt.getCompound("location"));
this.stack = ItemStack.read(nbt.getCompound("stack")); this.stack = ItemStack.read(nbt.getCompound("stack"));

View file

@ -12,12 +12,12 @@ import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NBTUtil; import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3d;
@ -67,7 +67,7 @@ public class PipeItem implements IPipeItem {
this(TYPE, stack, speed); this(TYPE, stack, speed);
} }
public PipeItem(ResourceLocation type, CompoundNBT nbt) { public PipeItem(ResourceLocation type, CompoundTag nbt) {
this.type = type; this.type = type;
this.path = new ArrayList<>(); this.path = new ArrayList<>();
this.deserializeNBT(nbt); this.deserializeNBT(nbt);
@ -244,8 +244,8 @@ public class PipeItem implements IPipeItem {
} }
@Override @Override
public CompoundNBT serializeNBT() { public CompoundTag serializeNBT() {
CompoundNBT nbt = new CompoundNBT(); CompoundTag nbt = new CompoundTag();
nbt.putString("type", this.type.toString()); nbt.putString("type", this.type.toString());
nbt.put("stack", this.stack.serializeNBT()); nbt.put("stack", this.stack.serializeNBT());
nbt.putFloat("speed", this.speed); nbt.putFloat("speed", this.speed);
@ -257,7 +257,7 @@ public class PipeItem implements IPipeItem {
nbt.putFloat("x", this.x); nbt.putFloat("x", this.x);
nbt.putFloat("y", this.y); nbt.putFloat("y", this.y);
nbt.putFloat("z", this.z); nbt.putFloat("z", this.z);
ListNBT list = new ListNBT(); ListTag list = new ListTag();
for (BlockPos pos : this.path) for (BlockPos pos : this.path)
list.add(NBTUtil.writeBlockPos(pos)); list.add(NBTUtil.writeBlockPos(pos));
nbt.put("path", list); nbt.put("path", list);
@ -265,7 +265,7 @@ public class PipeItem implements IPipeItem {
} }
@Override @Override
public void deserializeNBT(CompoundNBT nbt) { public void deserializeNBT(CompoundTag nbt) {
this.stack = ItemStack.read(nbt.getCompound("stack")); this.stack = ItemStack.read(nbt.getCompound("stack"));
this.speed = nbt.getFloat("speed"); this.speed = nbt.getFloat("speed");
this.startInventory = NBTUtil.readBlockPos(nbt.getCompound("start_inv")); this.startInventory = NBTUtil.readBlockPos(nbt.getCompound("start_inv"));
@ -277,7 +277,7 @@ public class PipeItem implements IPipeItem {
this.y = nbt.getFloat("y"); this.y = nbt.getFloat("y");
this.z = nbt.getFloat("z"); this.z = nbt.getFloat("z");
this.path.clear(); this.path.clear();
ListNBT list = nbt.getList("path", Constants.NBT.TAG_COMPOUND); ListTag list = nbt.getList("path", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < list.size(); i++) for (int i = 0; i < list.size(); i++)
this.path.add(NBTUtil.readBlockPos(list.getCompound(i))); this.path.add(NBTUtil.readBlockPos(list.getCompound(i)));
} }

View file

@ -13,13 +13,18 @@ import de.ellpeck.prettypipes.pipe.IPipeItem;
import de.ellpeck.prettypipes.pipe.PipeBlock; import de.ellpeck.prettypipes.pipe.PipeBlock;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.core.Direction;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.*;
import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NBTUtil; import net.minecraft.nbt.NBTUtil;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.common.util.Constants.NBT;
@ -46,7 +51,7 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphListener<BlockPos, NetworkEdge> { public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphListener<BlockPos, NetworkEdge> {
public final ListenableGraph<BlockPos, NetworkEdge> graph; public final ListenableGraph<BlockPos, NetworkEdge> graph;
private final DijkstraShortestPath<BlockPos, NetworkEdge> dijkstra; private final DijkstraShortestPath<BlockPos, NetworkEdge> dijkstra;
@ -54,10 +59,10 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
private final Map<BlockPos, PipeTileEntity> tileCache = new HashMap<>(); private final Map<BlockPos, PipeTileEntity> tileCache = new HashMap<>();
private final ListMultimap<BlockPos, IPipeItem> pipeItems = ArrayListMultimap.create(); private final ListMultimap<BlockPos, IPipeItem> pipeItems = ArrayListMultimap.create();
private final ListMultimap<BlockPos, NetworkLock> networkLocks = ArrayListMultimap.create(); private final ListMultimap<BlockPos, NetworkLock> networkLocks = ArrayListMultimap.create();
private final World world; private final Level world;
private final LazyOptional<PipeNetwork> lazyThis = LazyOptional.of(() -> this); private final LazyOptional<PipeNetwork> lazyThis = LazyOptional.of(() -> this);
public PipeNetwork(World world) { public PipeNetwork(Level world) {
this.world = world; this.world = world;
this.graph = new DefaultListenableGraph<>(new SimpleWeightedGraph<>(NetworkEdge.class)); this.graph = new DefaultListenableGraph<>(new SimpleWeightedGraph<>(NetworkEdge.class));
this.graph.addGraphListener(this); this.graph.addGraphListener(this);
@ -71,13 +76,13 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
} }
@Override @Override
public CompoundNBT serializeNBT() { public CompoundTag serializeNBT() {
CompoundNBT nbt = new CompoundNBT(); CompoundTag nbt = new CompoundTag();
ListNBT nodes = new ListNBT(); ListTag nodes = new ListTag();
for (BlockPos node : this.graph.vertexSet()) for (BlockPos node : this.graph.vertexSet())
nodes.add(NBTUtil.writeBlockPos(node)); nodes.add(NbtUtils.writeBlockPos(node));
nbt.put("nodes", nodes); nbt.put("nodes", nodes);
ListNBT edges = new ListNBT(); ListTag edges = new ListTag();
for (NetworkEdge edge : this.graph.edgeSet()) for (NetworkEdge edge : this.graph.edgeSet())
edges.add(edge.serializeNBT()); edges.add(edge.serializeNBT());
nbt.put("edges", edges); nbt.put("edges", edges);
@ -87,15 +92,15 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
} }
@Override @Override
public void deserializeNBT(CompoundNBT nbt) { public void deserializeNBT(CompoundTag nbt) {
this.graph.removeAllVertices(new ArrayList<>(this.graph.vertexSet())); this.graph.removeAllVertices(new ArrayList<>(this.graph.vertexSet()));
this.pipeItems.clear(); this.pipeItems.clear();
this.networkLocks.clear(); this.networkLocks.clear();
ListNBT nodes = nbt.getList("nodes", NBT.TAG_COMPOUND); ListTag nodes = nbt.getList("nodes", Tag.TAG_COMPOUND);
for (int i = 0; i < nodes.size(); i++) for (int i = 0; i < nodes.size(); i++)
this.graph.addVertex(NBTUtil.readBlockPos(nodes.getCompound(i))); this.graph.addVertex(NBTUtil.readBlockPos(nodes.getCompound(i)));
ListNBT edges = nbt.getList("edges", NBT.TAG_COMPOUND); ListTag edges = nbt.getList("edges", Tag.TAG_COMPOUND);
for (int i = 0; i < edges.size(); i++) for (int i = 0; i < edges.size(); i++)
this.addEdge(new NetworkEdge(edges.getCompound(i))); this.addEdge(new NetworkEdge(edges.getCompound(i)));
for (IPipeItem item : Utility.deserializeAll(nbt.getList("items", NBT.TAG_COMPOUND), IPipeItem::load)) for (IPipeItem item : Utility.deserializeAll(nbt.getList("items", NBT.TAG_COMPOUND), IPipeItem::load))
@ -247,7 +252,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
public PipeTileEntity getPipe(BlockPos pos) { public PipeTileEntity getPipe(BlockPos pos) {
PipeTileEntity tile = this.tileCache.get(pos); PipeTileEntity tile = this.tileCache.get(pos);
if (tile == null || tile.isRemoved()) { if (tile == null || tile.isRemoved()) {
tile = Utility.getTileEntity(PipeTileEntity.class, this.world, pos); tile = Utility.getBlockEntity(PipeTileEntity.class, this.world, pos);
this.tileCache.put(pos, tile); this.tileCache.put(pos, tile);
} }
return tile; return tile;
@ -517,7 +522,7 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundNBT>, GraphL
this.world.getProfiler().endSection(); this.world.getProfiler().endSection();
} }
public static PipeNetwork get(World world) { public static PipeNetwork get(Level world) {
return world.getCapability(Registry.pipeNetworkCapability).orElse(null); return world.getCapability(Registry.pipeNetworkCapability).orElse(null);
} }

View file

@ -17,7 +17,7 @@ import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
@ -77,7 +77,7 @@ public class PacketButton {
public enum ButtonResult { public enum ButtonResult {
PIPE_TAB((pos, data, player) -> { PIPE_TAB((pos, data, player) -> {
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, player.world, pos); PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, player.world, pos);
if (data[0] < 0) { if (data[0] < 0) {
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos); NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos);
} else { } else {
@ -113,11 +113,11 @@ public class PacketButton {
StackSizeModuleItem.setMaxStackSize(container.moduleStack, data[0]); StackSizeModuleItem.setMaxStackSize(container.moduleStack, data[0]);
}), }),
CRAFT_TERMINAL_REQUEST((pos, data, player) -> { CRAFT_TERMINAL_REQUEST((pos, data, player) -> {
CraftingTerminalTileEntity tile = Utility.getTileEntity(CraftingTerminalTileEntity.class, player.world, pos); CraftingTerminalTileEntity tile = Utility.getBlockEntity(CraftingTerminalTileEntity.class, player.world, pos);
tile.requestCraftingItems(player, data[0]); tile.requestCraftingItems(player, data[0]);
}), }),
CANCEL_CRAFTING((pos, data, player) -> { CANCEL_CRAFTING((pos, data, player) -> {
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, pos); ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, player.world, pos);
tile.cancelCrafting(); tile.cancelCrafting();
}), }),
TAG_FILTER((pos, data, player) -> { TAG_FILTER((pos, data, player) -> {

View file

@ -2,7 +2,7 @@ package de.ellpeck.prettypipes.packets;
import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer; import de.ellpeck.prettypipes.pipe.modules.craft.CraftingModuleContainer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;

View file

@ -6,7 +6,7 @@ import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity; import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
@ -50,7 +50,7 @@ public class PacketGhostSlot {
@SuppressWarnings("Convert2Lambda") @SuppressWarnings("Convert2Lambda")
public static void onMessage(PacketGhostSlot message, Supplier<NetworkEvent.Context> ctx) { public static void onMessage(PacketGhostSlot message, Supplier<NetworkEvent.Context> ctx) {
Consumer<PlayerEntity> doIt = p -> { Consumer<PlayerEntity> doIt = p -> {
CraftingTerminalTileEntity tile = Utility.getTileEntity(CraftingTerminalTileEntity.class, p.world, message.pos); CraftingTerminalTileEntity tile = Utility.getBlockEntity(CraftingTerminalTileEntity.class, p.world, message.pos);
if (tile != null) if (tile != null)
tile.setGhostItems(message.stacks); tile.setGhostItems(message.stacks);
}; };

View file

@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.packets;
import de.ellpeck.prettypipes.PrettyPipes; import de.ellpeck.prettypipes.PrettyPipes;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.World; import net.minecraft.world.World;

View file

@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.pipe.IPipeItem; import de.ellpeck.prettypipes.pipe.IPipeItem;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
@ -14,7 +14,7 @@ import java.util.function.Supplier;
public class PacketItemEnterPipe { public class PacketItemEnterPipe {
private BlockPos tilePos; private BlockPos tilePos;
private CompoundNBT item; private CompoundTag item;
public PacketItemEnterPipe(BlockPos tilePos, IPipeItem item) { public PacketItemEnterPipe(BlockPos tilePos, IPipeItem item) {
this.tilePos = tilePos; this.tilePos = tilePos;
@ -46,7 +46,7 @@ public class PacketItemEnterPipe {
if (mc.world == null) if (mc.world == null)
return; return;
IPipeItem item = IPipeItem.load(message.item); IPipeItem item = IPipeItem.load(message.item);
PipeTileEntity pipe = Utility.getTileEntity(PipeTileEntity.class, mc.world, message.tilePos); PipeTileEntity pipe = Utility.getBlockEntity(PipeTileEntity.class, mc.world, message.tilePos);
if (pipe != null) if (pipe != null)
pipe.getItems().add(item); pipe.getItems().add(item);
} }

View file

@ -4,8 +4,8 @@ import de.ellpeck.prettypipes.terminal.containers.ItemTerminalGui;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;

View file

@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.packets;
import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
@ -46,7 +46,7 @@ public class PacketRequest {
@Override @Override
public void run() { public void run() {
PlayerEntity player = ctx.get().getSender(); PlayerEntity player = ctx.get().getSender();
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, message.pos); ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, player.world, message.pos);
message.stack.setCount(message.amount); message.stack.setCount(message.amount);
tile.requestItem(player, message.stack); tile.requestItem(player, message.stack);
} }

View file

@ -1,10 +1,10 @@
package de.ellpeck.prettypipes.pipe; package de.ellpeck.prettypipes.pipe;
import net.minecraft.util.IStringSerializable; import net.minecraft.util.StringRepresentable;
import java.util.Locale; import java.util.Locale;
public enum ConnectionType implements IStringSerializable { public enum ConnectionType implements StringRepresentable {
CONNECTED(true), CONNECTED(true),
DISCONNECTED(false), DISCONNECTED(false),
BLOCKED(false), BLOCKED(false),
@ -23,7 +23,7 @@ public enum ConnectionType implements IStringSerializable {
} }
@Override @Override
public String getString() { public String getSerializedName() {
return this.name; return this.name;
} }
} }

View file

@ -1,6 +1,6 @@
package de.ellpeck.prettypipes.pipe; package de.ellpeck.prettypipes.pipe;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;

View file

@ -6,9 +6,9 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import de.ellpeck.prettypipes.network.NetworkEdge; import de.ellpeck.prettypipes.network.NetworkEdge;
import de.ellpeck.prettypipes.network.PipeItem; import de.ellpeck.prettypipes.network.PipeItem;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
@ -22,9 +22,9 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.function.BiFunction; import java.util.function.BiFunction;
public interface IPipeItem extends INBTSerializable<CompoundNBT> { public interface IPipeItem extends INBTSerializable<CompoundTag> {
Map<ResourceLocation, BiFunction<ResourceLocation, CompoundNBT, IPipeItem>> TYPES = new HashMap<>( Map<ResourceLocation, BiFunction<ResourceLocation, CompoundTag, IPipeItem>> TYPES = new HashMap<>(
Collections.singletonMap(PipeItem.TYPE, PipeItem::new)); Collections.singletonMap(PipeItem.TYPE, PipeItem::new));
ItemStack getContent(); ItemStack getContent();
@ -46,13 +46,13 @@ public interface IPipeItem extends INBTSerializable<CompoundNBT> {
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
void render(PipeTileEntity tile, MatrixStack matrixStack, Random random, float partialTicks, int light, int overlay, IRenderTypeBuffer buffer); void render(PipeTileEntity tile, MatrixStack matrixStack, Random random, float partialTicks, int light, int overlay, IRenderTypeBuffer buffer);
static IPipeItem load(CompoundNBT nbt) { static IPipeItem load(CompoundTag nbt) {
// TODO legacy compat, remove eventually // TODO legacy compat, remove eventually
if (!nbt.contains("type")) if (!nbt.contains("type"))
nbt.putString("type", PipeItem.TYPE.toString()); nbt.putString("type", PipeItem.TYPE.toString());
ResourceLocation type = new ResourceLocation(nbt.getString("type")); ResourceLocation type = new ResourceLocation(nbt.getString("type"));
BiFunction<ResourceLocation, CompoundNBT, IPipeItem> func = TYPES.get(type); BiFunction<ResourceLocation, CompoundTag, IPipeItem> func = TYPES.get(type);
return func != null ? func.apply(type, nbt) : null; return func != null ? func.apply(type, nbt) : null;
} }
} }

View file

@ -7,13 +7,19 @@ import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.network.PipeNetwork;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.fluid.FluidState; import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids; import net.minecraft.fluid.Fluids;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.state.EnumProperty; import net.minecraft.state.EnumProperty;
import net.minecraft.state.StateContainer; import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.BlockStateProperties;
@ -31,10 +37,21 @@ import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.network.NetworkHooks;
import org.apache.commons.lang3.mutable.MutableObject; import org.apache.commons.lang3.mutable.MutableObject;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -43,57 +60,57 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
public class PipeBlock extends ContainerBlock { public class PipeBlock extends BaseEntityBlock {
public static final Map<Direction, EnumProperty<ConnectionType>> DIRECTIONS = new HashMap<>(); public static final Map<Direction, EnumProperty<ConnectionType>> DIRECTIONS = new HashMap<>();
private static final Map<Pair<BlockState, BlockState>, VoxelShape> SHAPE_CACHE = new HashMap<>(); private static final Map<Pair<BlockState, BlockState>, VoxelShape> SHAPE_CACHE = new HashMap<>();
private static final Map<Pair<BlockState, BlockState>, VoxelShape> COLL_SHAPE_CACHE = new HashMap<>(); private static final Map<Pair<BlockState, BlockState>, VoxelShape> COLL_SHAPE_CACHE = new HashMap<>();
private static final VoxelShape CENTER_SHAPE = makeCuboidShape(5, 5, 5, 11, 11, 11); private static final VoxelShape CENTER_SHAPE = box(5, 5, 5, 11, 11, 11);
public static final Map<Direction, VoxelShape> DIR_SHAPES = ImmutableMap.<Direction, VoxelShape>builder() public static final Map<Direction, VoxelShape> DIR_SHAPES = ImmutableMap.<Direction, VoxelShape>builder()
.put(Direction.UP, makeCuboidShape(5, 10, 5, 11, 16, 11)) .put(Direction.UP, box(5, 10, 5, 11, 16, 11))
.put(Direction.DOWN, makeCuboidShape(5, 0, 5, 11, 6, 11)) .put(Direction.DOWN, box(5, 0, 5, 11, 6, 11))
.put(Direction.NORTH, makeCuboidShape(5, 5, 0, 11, 11, 6)) .put(Direction.NORTH, box(5, 5, 0, 11, 11, 6))
.put(Direction.SOUTH, makeCuboidShape(5, 5, 10, 11, 11, 16)) .put(Direction.SOUTH, box(5, 5, 10, 11, 11, 16))
.put(Direction.EAST, makeCuboidShape(10, 5, 5, 16, 11, 11)) .put(Direction.EAST, box(10, 5, 5, 16, 11, 11))
.put(Direction.WEST, makeCuboidShape(0, 5, 5, 6, 11, 11)) .put(Direction.WEST, box(0, 5, 5, 6, 11, 11))
.build(); .build();
static { static {
for (Direction dir : Direction.values()) for (Direction dir : Direction.values())
DIRECTIONS.put(dir, EnumProperty.create(dir.getName2(), ConnectionType.class)); DIRECTIONS.put(dir, EnumProperty.create(dir.getName(), ConnectionType.class));
} }
public PipeBlock() { public PipeBlock() {
super(Block.Properties.create(Material.ROCK).hardnessAndResistance(2).sound(SoundType.STONE).notSolid()); super(Block.Properties.of(Material.STONE).strength(2).sound(SoundType.STONE).noOcclusion());
BlockState state = this.getDefaultState().with(BlockStateProperties.WATERLOGGED, false); BlockState state = this.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, false);
for (EnumProperty<ConnectionType> prop : DIRECTIONS.values()) for (EnumProperty<ConnectionType> prop : DIRECTIONS.values())
state = state.with(prop, ConnectionType.DISCONNECTED); state = state.setValue(prop, ConnectionType.DISCONNECTED);
this.setDefaultState(state); this.registerDefaultState(state);
} }
@Override @Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) { public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos); PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos);
if (tile == null) if (tile == null)
return ActionResultType.PASS; return InteractionResult.PASS;
if (!tile.canHaveModules()) if (!tile.canHaveModules())
return ActionResultType.PASS; return InteractionResult.PASS;
ItemStack stack = player.getHeldItem(handIn); ItemStack stack = player.getItemInHand(handIn);
if (stack.getItem() instanceof IModule) { if (stack.getItem() instanceof IModule) {
ItemStack copy = stack.copy(); ItemStack copy = stack.copy();
copy.setCount(1); copy.setCount(1);
ItemStack remain = ItemHandlerHelper.insertItem(tile.modules, copy, false); ItemStack remain = ItemHandlerHelper.insertItem(tile.modules, copy, false);
if (remain.isEmpty()) { if (remain.isEmpty()) {
stack.shrink(1); stack.shrink(1);
return ActionResultType.SUCCESS; return InteractionResult.SUCCESS;
} }
} else if (handIn == Hand.MAIN_HAND && stack.isEmpty()) { } else if (handIn == InteractionHand.MAIN_HAND && stack.isEmpty()) {
if (!worldIn.isRemote) if (!worldIn.isClientSide)
NetworkHooks.openGui((ServerPlayerEntity) player, tile, pos); NetworkHooks.openGui((ServerPlayer) player, tile, pos);
return ActionResultType.SUCCESS; return InteractionResult.SUCCESS;
} }
return ActionResultType.PASS; return InteractionResult.PASS;
} }
@Override @Override
@ -152,7 +169,7 @@ public class PipeBlock extends ContainerBlock {
private VoxelShape cacheAndGetShape(BlockState state, IBlockReader worldIn, BlockPos pos, Function<BlockState, VoxelShape> coverShapeSelector, Map<Pair<BlockState, BlockState>, VoxelShape> cache, Function<VoxelShape, VoxelShape> shapeModifier) { private VoxelShape cacheAndGetShape(BlockState state, IBlockReader worldIn, BlockPos pos, Function<BlockState, VoxelShape> coverShapeSelector, Map<Pair<BlockState, BlockState>, VoxelShape> cache, Function<VoxelShape, VoxelShape> shapeModifier) {
VoxelShape coverShape = null; VoxelShape coverShape = null;
BlockState cover = null; BlockState cover = null;
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos); PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos);
if (tile != null && tile.cover != null) { if (tile != null && tile.cover != null) {
cover = tile.cover; cover = tile.cover;
// try catch since the block might expect to find itself at the position // try catch since the block might expect to find itself at the position
@ -230,7 +247,7 @@ public class PipeBlock extends ContainerBlock {
public static void onStateChanged(World world, BlockPos pos, BlockState newState) { public static void onStateChanged(World world, BlockPos pos, BlockState newState) {
// wait a few ticks before checking if we have to drop our modules, so that things like iron -> gold chest work // wait a few ticks before checking if we have to drop our modules, so that things like iron -> gold chest work
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, world, pos); PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, world, pos);
if (tile != null) if (tile != null)
tile.moduleDropCheck = 5; tile.moduleDropCheck = 5;
@ -280,7 +297,7 @@ public class PipeBlock extends ContainerBlock {
@Override @Override
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) {
PipeTileEntity pipe = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos); PipeTileEntity pipe = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos);
if (pipe == null) if (pipe == null)
return 0; return 0;
return Math.min(15, pipe.getItems().size()); return Math.min(15, pipe.getItems().size());
@ -298,7 +315,7 @@ public class PipeBlock extends ContainerBlock {
} }
public static void dropItems(World worldIn, BlockPos pos, PlayerEntity player) { public static void dropItems(World worldIn, BlockPos pos, PlayerEntity player) {
PipeTileEntity tile = Utility.getTileEntity(PipeTileEntity.class, worldIn, pos); PipeTileEntity tile = Utility.getBlockEntity(PipeTileEntity.class, worldIn, pos);
if (tile != null) { if (tile != null) {
Utility.dropInventory(tile, tile.modules); Utility.dropInventory(tile, tile.modules);
for (IPipeItem item : tile.getItems()) for (IPipeItem item : tile.getItems())

View file

@ -9,17 +9,19 @@ import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.network.NetworkLock; import de.ellpeck.prettypipes.network.NetworkLock;
import de.ellpeck.prettypipes.network.PipeNetwork; import de.ellpeck.prettypipes.network.PipeNetwork;
import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer; import de.ellpeck.prettypipes.pipe.containers.MainPipeContainer;
import de.ellpeck.prettypipes.pressurizer.PressurizerTileEntity; import de.ellpeck.prettypipes.pressurizer.PressurizerBlockEntity;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.NbtUtils;
import net.minecraft.nbt.ListNBT; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NBTUtil; import net.minecraft.nbt.NBTUtil;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.network.play.server.SUpdateTileEntityPacket;
@ -33,6 +35,8 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -53,15 +57,14 @@ import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class PipeTileEntity extends TileEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable { public class PipeTileEntity extends BlockEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable {
public final ItemStackHandler modules = new ItemStackHandler(3) { public final ItemStackHandler modules = new ItemStackHandler(3) {
@Override @Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) { public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
Item item = stack.getItem(); var item = stack.getItem();
if (!(item instanceof IModule)) if (!(item instanceof IModule module))
return false; return false;
IModule module = (IModule) item;
return PipeTileEntity.this.streamModules().allMatch(m -> module.isCompatible(stack, PipeTileEntity.this, m.getRight()) && m.getRight().isCompatible(m.getLeft(), PipeTileEntity.this, module)); return PipeTileEntity.this.streamModules().allMatch(m -> module.isCompatible(stack, PipeTileEntity.this, m.getRight()) && m.getRight().isCompatible(m.getLeft(), PipeTileEntity.this, module));
} }
@ -72,74 +75,66 @@ public class PipeTileEntity extends TileEntity implements INamedContainerProvide
}; };
public final Queue<NetworkLock> craftIngredientRequests = new LinkedList<>(); public final Queue<NetworkLock> craftIngredientRequests = new LinkedList<>();
public final List<Pair<BlockPos, ItemStack>> craftResultRequests = new ArrayList<>(); public final List<Pair<BlockPos, ItemStack>> craftResultRequests = new ArrayList<>();
public PressurizerTileEntity pressurizer; public PressurizerBlockEntity pressurizer;
public BlockState cover; public BlockState cover;
public int moduleDropCheck; public int moduleDropCheck;
protected List<IPipeItem> items; protected List<IPipeItem> items;
private int lastItemAmount; private int lastItemAmount;
private int priority; private int priority;
private final LazyOptional<PipeTileEntity> lazyThis = LazyOptional.of(() -> this); private final LazyOptional<PipeTileEntity> lazyThis = LazyOptional.of(() -> this);
private final Lazy<Integer> workRandomizer = Lazy.of(() -> this.world.rand.nextInt(200)); private final Lazy<Integer> workRandomizer = Lazy.of(() -> this.level.random.nextInt(200));
public PipeTileEntity() {
this(Registry.pipeTileEntity);
}
protected PipeTileEntity(TileEntityType<?> type) {
super(type);
}
@Override @Override
public void onChunkUnloaded() { public void onChunkUnloaded() {
PipeNetwork.get(this.world).uncachePipe(this.pos); PipeNetwork.get(this.level).uncachePipe(this.worldPosition);
} }
@Override @Override
public CompoundNBT write(CompoundNBT compound) { public CompoundTag save(CompoundTag compound) {
compound.put("modules", this.modules.serializeNBT()); compound.put("modules", this.modules.serializeNBT());
compound.putInt("module_drop_check", this.moduleDropCheck); compound.putInt("module_drop_check", this.moduleDropCheck);
compound.put("requests", Utility.serializeAll(this.craftIngredientRequests)); compound.put("requests", Utility.serializeAll(this.craftIngredientRequests));
if (this.cover != null) if (this.cover != null)
compound.put("cover", NBTUtil.writeBlockState(this.cover)); compound.put("cover", NbtUtils.writeBlockState(this.cover));
ListNBT results = new ListNBT(); ListTag results = new ListTag();
for (Pair<BlockPos, ItemStack> triple : this.craftResultRequests) { for (Pair<BlockPos, ItemStack> triple : this.craftResultRequests) {
CompoundNBT nbt = new CompoundNBT(); CompoundTag nbt = new CompoundTag();
nbt.putLong("dest_pipe", triple.getLeft().toLong()); nbt.putLong("dest_pipe", triple.getLeft().asLong());
nbt.put("item", triple.getRight().serializeNBT()); nbt.put("item", triple.getRight().serializeNBT());
results.add(nbt); results.add(nbt);
} }
compound.put("craft_results", results); compound.put("craft_results", results);
return super.write(compound); return super.save(compound);
} }
@Override @Override
public void read(BlockState state, CompoundNBT compound) { public void load(CompoundTag compound) {
this.modules.deserializeNBT(compound.getCompound("modules")); this.modules.deserializeNBT(compound.getCompound("modules"));
this.moduleDropCheck = compound.getInt("module_drop_check"); this.moduleDropCheck = compound.getInt("module_drop_check");
this.cover = compound.contains("cover") ? NBTUtil.readBlockState(compound.getCompound("cover")) : null; this.cover = compound.contains("cover") ? NbtUtils.readBlockState(compound.getCompound("cover")) : null;
this.craftIngredientRequests.clear(); this.craftIngredientRequests.clear();
this.craftIngredientRequests.addAll(Utility.deserializeAll(compound.getList("requests", NBT.TAG_COMPOUND), NetworkLock::new)); this.craftIngredientRequests.addAll(Utility.deserializeAll(compound.getList("requests", NBT.TAG_COMPOUND), NetworkLock::new));
this.craftResultRequests.clear(); this.craftResultRequests.clear();
ListNBT results = compound.getList("craft_results", NBT.TAG_COMPOUND); ListTag results = compound.getList("craft_results", NBT.TAG_COMPOUND);
for (int i = 0; i < results.size(); i++) { for (int i = 0; i < results.size(); i++) {
CompoundNBT nbt = results.getCompound(i); CompoundTag nbt = results.getCompound(i);
this.craftResultRequests.add(Pair.of( this.craftResultRequests.add(Pair.of(
BlockPos.fromLong(nbt.getLong("dest_pipe")), BlockPos.of(nbt.getLong("dest_pipe")),
ItemStack.read(nbt.getCompound("item")))); ItemStack.of(nbt.getCompound("item"))));
} }
super.read(state, compound); super.load(compound);
} }
@Override @Override
public CompoundNBT getUpdateTag() { public CompoundTag getUpdateTag() {
// sync pipe items on load // sync pipe items on load
CompoundNBT nbt = this.write(new CompoundNBT()); CompoundTag nbt = this.write(new CompoundTag());
nbt.put("items", Utility.serializeAll(this.getItems())); nbt.put("items", Utility.serializeAll(this.getItems()));
return nbt; return nbt;
} }
@Override @Override
public void handleUpdateTag(BlockState state, CompoundNBT nbt) { public void handleUpdateTag(BlockState state, CompoundTag nbt) {
this.read(state, nbt); this.read(state, nbt);
List<IPipeItem> items = this.getItems(); List<IPipeItem> items = this.getItems();
items.clear(); items.clear();

View file

@ -9,7 +9,7 @@ import net.minecraft.inventory.container.ClickType;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.Slot; import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -24,7 +24,7 @@ public abstract class AbstractPipeContainer<T extends IModule> extends Container
public AbstractPipeContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) { public AbstractPipeContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos, int moduleIndex) {
super(type, id); super(type, id);
this.tile = Utility.getTileEntity(PipeTileEntity.class, player.world, pos); this.tile = Utility.getBlockEntity(PipeTileEntity.class, player.world, pos);
this.moduleStack = moduleIndex < 0 ? null : this.tile.modules.getStackInSlot(moduleIndex); this.moduleStack = moduleIndex < 0 ? null : this.tile.modules.getStackInSlot(moduleIndex);
this.module = moduleIndex < 0 ? null : (T) this.moduleStack.getItem(); this.module = moduleIndex < 0 ? null : (T) this.moduleStack.getItem();
this.moduleIndex = moduleIndex; this.moduleIndex = moduleIndex;

View file

@ -11,8 +11,8 @@ import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.Widget;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Slot; import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.SoundEvents; import net.minecraft.util.SoundEvents;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;

View file

@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleItem;
import de.ellpeck.prettypipes.items.ModuleTier; import de.ellpeck.prettypipes.items.ModuleTier;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
public class HighPriorityModuleItem extends ModuleItem { public class HighPriorityModuleItem extends ModuleItem {
private final int priority; private final int priority;

View file

@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleItem;
import de.ellpeck.prettypipes.items.ModuleTier; import de.ellpeck.prettypipes.items.ModuleTier;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
public class LowPriorityModuleItem extends ModuleItem { public class LowPriorityModuleItem extends ModuleItem {
private final int priority; private final int priority;

View file

@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.pipe.modules;
import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleItem;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
public class RedstoneModuleItem extends ModuleItem { public class RedstoneModuleItem extends ModuleItem {

View file

@ -3,7 +3,7 @@ package de.ellpeck.prettypipes.pipe.modules;
import de.ellpeck.prettypipes.items.IModule; import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleItem;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.util.List; import java.util.List;

View file

@ -4,7 +4,7 @@ import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.items.ModuleItem; import de.ellpeck.prettypipes.items.ModuleItem;
import de.ellpeck.prettypipes.items.ModuleTier; import de.ellpeck.prettypipes.items.ModuleTier;
import de.ellpeck.prettypipes.pipe.PipeTileEntity; import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
public class SpeedModuleItem extends ModuleItem { public class SpeedModuleItem extends ModuleItem {
private final float speedIncrease; private final float speedIncrease;

View file

@ -15,8 +15,8 @@ import de.ellpeck.prettypipes.terminal.CraftingTerminalTileEntity;
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.ItemStackHandler;
@ -208,7 +208,7 @@ public class CraftingModuleItem extends ModuleItem {
} }
public void save(ItemStackHandler input, ItemStackHandler output, ItemStack module) { public void save(ItemStackHandler input, ItemStackHandler output, ItemStack module) {
CompoundNBT tag = module.getOrCreateTag(); CompoundTag tag = module.getOrCreateTag();
if (input != null) if (input != null)
tag.put("input", input.serializeNBT()); tag.put("input", input.serializeNBT());
if (output != null) if (output != null)

View file

@ -10,7 +10,7 @@ import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;

View file

@ -8,7 +8,7 @@ import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
public class FilterIncreaseModuleItem extends ModuleItem { public class FilterIncreaseModuleItem extends ModuleItem {

View file

@ -9,7 +9,7 @@ import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
public class FilterModuleItem extends ModuleItem { public class FilterModuleItem extends ModuleItem {

View file

@ -4,8 +4,8 @@ import de.ellpeck.prettypipes.misc.ItemFilter;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import javax.annotation.Nullable; import javax.annotation.Nullable;

View file

@ -5,7 +5,7 @@ import de.ellpeck.prettypipes.packets.PacketButton;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeGui;
import net.minecraft.client.audio.SimpleSound; import net.minecraft.client.audio.SimpleSound;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.SoundEvents; import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;

View file

@ -10,8 +10,8 @@ import joptsimple.internal.Strings;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;

View file

@ -11,7 +11,7 @@ import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;

View file

@ -8,7 +8,7 @@ import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer; import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
public class StackSizeModuleItem extends ModuleItem { public class StackSizeModuleItem extends ModuleItem {

View file

@ -9,7 +9,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
@ -31,7 +31,7 @@ public class PressurizerBlock extends ContainerBlock {
@Override @Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) {
PressurizerTileEntity tile = Utility.getTileEntity(PressurizerTileEntity.class, worldIn, pos); PressurizerBlockEntity tile = Utility.getBlockEntity(PressurizerBlockEntity.class, worldIn, pos);
if (tile == null) if (tile == null)
return ActionResultType.PASS; return ActionResultType.PASS;
if (!worldIn.isRemote) if (!worldIn.isRemote)
@ -41,7 +41,7 @@ public class PressurizerBlock extends ContainerBlock {
@Override @Override
public TileEntity createNewTileEntity(IBlockReader worldIn) { public TileEntity createNewTileEntity(IBlockReader worldIn) {
return new PressurizerTileEntity(); return new PressurizerBlockEntity();
} }
@Override @Override

View file

@ -12,8 +12,8 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableTileEntity;
@ -24,6 +24,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.CapabilityEnergy;
@ -32,14 +33,14 @@ import net.minecraftforge.energy.IEnergyStorage;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class PressurizerTileEntity extends TileEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable { public class PressurizerBlockEntity extends BlockEntity implements INamedContainerProvider, ITickableTileEntity, IPipeConnectable {
private final ModifiableEnergyStorage storage = new ModifiableEnergyStorage(64000, 512, 0); private final ModifiableEnergyStorage storage = new ModifiableEnergyStorage(64000, 512, 0);
private final LazyOptional<IEnergyStorage> lazyStorage = LazyOptional.of(() -> this.storage); private final LazyOptional<IEnergyStorage> lazyStorage = LazyOptional.of(() -> this.storage);
private final LazyOptional<IPipeConnectable> lazyThis = LazyOptional.of(() -> this); private final LazyOptional<IPipeConnectable> lazyThis = LazyOptional.of(() -> this);
private int lastEnergy; private int lastEnergy;
public PressurizerTileEntity() { public PressurizerBlockEntity() {
super(Registry.pressurizerTileEntity); super(Registry.pressurizerTileEntity);
} }
@ -61,24 +62,24 @@ public class PressurizerTileEntity extends TileEntity implements INamedContainer
} }
@Override @Override
public CompoundNBT write(CompoundNBT compound) { public CompoundTag write(CompoundTag compound) {
compound.putInt("energy", this.getEnergy()); compound.putInt("energy", this.getEnergy());
return super.write(compound); return super.write(compound);
} }
@Override @Override
public void read(BlockState state, CompoundNBT nbt) { public void read(BlockState state, CompoundTag nbt) {
this.storage.setEnergyStored(nbt.getInt("energy")); this.storage.setEnergyStored(nbt.getInt("energy"));
super.read(state, nbt); super.read(state, nbt);
} }
@Override @Override
public CompoundNBT getUpdateTag() { public CompoundTag getUpdateTag() {
return this.write(new CompoundNBT()); return this.write(new CompoundTag());
} }
@Override @Override
public void handleUpdateTag(BlockState state, CompoundNBT tag) { public void handleUpdateTag(BlockState state, CompoundTag tag) {
this.read(state, tag); this.read(state, tag);
} }
@ -138,7 +139,7 @@ public class PressurizerTileEntity extends TileEntity implements INamedContainer
// send energy update // send energy update
if (this.lastEnergy != this.storage.getEnergyStored() && this.world.getGameTime() % 10 == 0) { if (this.lastEnergy != this.storage.getEnergyStored() && this.world.getGameTime() % 10 == 0) {
this.lastEnergy = this.storage.getEnergyStored(); this.lastEnergy = this.storage.getEnergyStored();
Utility.sendTileEntityToClients(this); Utility.sendBlockEntityToClients(this);
} }
} }

View file

@ -1,27 +1,32 @@
package de.ellpeck.prettypipes.pressurizer; package de.ellpeck.prettypipes.pressurizer;
import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.Utility;
import net.minecraft.core.BlockPos;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.Slot; import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class PressurizerContainer extends Container { public class PressurizerContainer extends AbstractContainerMenu {
public final PressurizerTileEntity tile; public final PressurizerBlockEntity tile;
public PressurizerContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos) { public PressurizerContainer(@Nullable MenuType<?> type, int id, Player player, BlockPos pos) {
super(type, id); super(type, id);
this.tile = Utility.getTileEntity(PressurizerTileEntity.class, player.world, pos); this.tile = Utility.getBlockEntity(PressurizerBlockEntity.class, player.level, pos);
for (int l = 0; l < 3; ++l) for (int l = 0; l < 3; ++l)
for (int j1 = 0; j1 < 9; ++j1) for (int j1 = 0; j1 < 9; ++j1)
this.addSlot(new Slot(player.inventory, j1 + l * 9 + 9, 8 + j1 * 18, 55 + l * 18)); this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + j1 * 18, 55 + l * 18));
for (int i1 = 0; i1 < 9; ++i1) for (int i1 = 0; i1 < 9; ++i1)
this.addSlot(new Slot(player.inventory, i1, 8 + i1 * 18, 113)); this.addSlot(new Slot(player.getInventory(), i1, 8 + i1 * 18, 113));
} }
@Override @Override

View file

@ -5,7 +5,7 @@ import de.ellpeck.prettypipes.PrettyPipes;
import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.client.gui.widget.Widget; import net.minecraft.client.gui.widget.Widget;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;

View file

@ -18,8 +18,8 @@ import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
@ -136,13 +136,13 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
} }
@Override @Override
public CompoundNBT write(CompoundNBT compound) { public CompoundTag write(CompoundTag compound) {
compound.put("craft_items", this.craftItems.serializeNBT()); compound.put("craft_items", this.craftItems.serializeNBT());
return super.write(compound); return super.write(compound);
} }
@Override @Override
public void read(BlockState state, CompoundNBT compound) { public void read(BlockState state, CompoundTag compound) {
this.craftItems.deserializeNBT(compound.getCompound("craft_items")); this.craftItems.deserializeNBT(compound.getCompound("craft_items"));
super.read(state, compound); super.read(state, compound);
} }
@ -161,7 +161,7 @@ public class CraftingTerminalTileEntity extends ItemTerminalTileEntity {
@Override @Override
public ItemStack insertItem(BlockPos pipePos, Direction direction, ItemStack remain, boolean simulate) { public ItemStack insertItem(BlockPos pipePos, Direction direction, ItemStack remain, boolean simulate) {
BlockPos pos = pipePos.offset(direction); BlockPos pos = pipePos.offset(direction);
CraftingTerminalTileEntity tile = Utility.getTileEntity(CraftingTerminalTileEntity.class, this.world, pos); CraftingTerminalTileEntity tile = Utility.getBlockEntity(CraftingTerminalTileEntity.class, this.world, pos);
if (tile != null) { if (tile != null) {
remain = remain.copy(); remain = remain.copy();
int lowestSlot = -1; int lowestSlot = -1;

View file

@ -1,10 +1,6 @@
package de.ellpeck.prettypipes.terminal; package de.ellpeck.prettypipes.terminal;
import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.network.PipeItem;
import de.ellpeck.prettypipes.pipe.ConnectionType;
import de.ellpeck.prettypipes.pipe.IPipeConnectable;
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.ContainerBlock; import net.minecraft.block.ContainerBlock;
@ -13,7 +9,7 @@ import net.minecraft.block.material.Material;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
@ -26,8 +22,6 @@ import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.fml.network.NetworkHooks;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; import java.util.List;
@ -41,7 +35,7 @@ public class ItemTerminalBlock extends ContainerBlock {
@Override @Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) { public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult result) {
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, worldIn, pos); ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, worldIn, pos);
if (tile == null) if (tile == null)
return ActionResultType.PASS; return ActionResultType.PASS;
String reason = tile.getInvalidTerminalReason(); String reason = tile.getInvalidTerminalReason();
@ -60,7 +54,7 @@ public class ItemTerminalBlock extends ContainerBlock {
@Override @Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) { if (state.getBlock() != newState.getBlock()) {
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, worldIn, pos); ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, worldIn, pos);
if (tile != null) if (tile != null)
Utility.dropInventory(tile, tile.items); Utility.dropInventory(tile, tile.items);
super.onReplaced(state, worldIn, pos, newState, isMoving); super.onReplaced(state, worldIn, pos, newState, isMoving);

View file

@ -20,8 +20,8 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.tileentity.TileEntityType;
@ -230,14 +230,14 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
} }
@Override @Override
public CompoundNBT write(CompoundNBT compound) { public CompoundTag write(CompoundTag compound) {
compound.put("items", this.items.serializeNBT()); compound.put("items", this.items.serializeNBT());
compound.put("requests", Utility.serializeAll(this.existingRequests)); compound.put("requests", Utility.serializeAll(this.existingRequests));
return super.write(compound); return super.write(compound);
} }
@Override @Override
public void read(BlockState state, CompoundNBT compound) { public void read(BlockState state, CompoundTag compound) {
this.items.deserializeNBT(compound.getCompound("items")); this.items.deserializeNBT(compound.getCompound("items"));
this.existingRequests.clear(); this.existingRequests.clear();
this.existingRequests.addAll(Utility.deserializeAll(compound.getList("requests", NBT.TAG_COMPOUND), NetworkLock::new)); this.existingRequests.addAll(Utility.deserializeAll(compound.getList("requests", NBT.TAG_COMPOUND), NetworkLock::new));
@ -270,7 +270,7 @@ public class ItemTerminalTileEntity extends TileEntity implements INamedContaine
@Override @Override
public ItemStack insertItem(BlockPos pipePos, Direction direction, ItemStack stack, boolean simulate) { public ItemStack insertItem(BlockPos pipePos, Direction direction, ItemStack stack, boolean simulate) {
BlockPos pos = pipePos.offset(direction); BlockPos pos = pipePos.offset(direction);
ItemTerminalTileEntity tile = Utility.getTileEntity(ItemTerminalTileEntity.class, world, pos); ItemTerminalTileEntity tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, world, pos);
if (tile != null) if (tile != null)
return ItemHandlerHelper.insertItemStacked(tile.items, stack, simulate); return ItemHandlerHelper.insertItemStacked(tile.items, stack, simulate);
return stack; return stack;

View file

@ -11,7 +11,7 @@ import net.minecraft.inventory.container.ClickType;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.CraftingResultSlot; import net.minecraft.inventory.container.CraftingResultSlot;
import net.minecraft.inventory.container.Slot; import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.item.crafting.ICraftingRecipe; import net.minecraft.item.crafting.ICraftingRecipe;
import net.minecraft.item.crafting.IRecipeType; import net.minecraft.item.crafting.IRecipeType;
import net.minecraft.network.play.server.SSetSlotPacket; import net.minecraft.network.play.server.SSetSlotPacket;

View file

@ -13,8 +13,8 @@ import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Slot; import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;

View file

@ -1,10 +1,6 @@
package de.ellpeck.prettypipes.terminal.containers; package de.ellpeck.prettypipes.terminal.containers;
import de.ellpeck.prettypipes.Utility; import de.ellpeck.prettypipes.Utility;
import de.ellpeck.prettypipes.network.NetworkItem;
import de.ellpeck.prettypipes.packets.PacketHandler;
import de.ellpeck.prettypipes.packets.PacketNetworkItems;
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity; import de.ellpeck.prettypipes.terminal.ItemTerminalTileEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity;
@ -12,16 +8,13 @@ import net.minecraft.inventory.container.ClickType;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.Slot; import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.items.SlotItemHandler; import net.minecraftforge.items.SlotItemHandler;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class ItemTerminalContainer extends Container { public class ItemTerminalContainer extends Container {
@ -29,7 +22,7 @@ public class ItemTerminalContainer extends Container {
public ItemTerminalContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos) { public ItemTerminalContainer(@Nullable ContainerType<?> type, int id, PlayerEntity player, BlockPos pos) {
super(type, id); super(type, id);
this.tile = Utility.getTileEntity(ItemTerminalTileEntity.class, player.world, pos); this.tile = Utility.getBlockEntity(ItemTerminalTileEntity.class, player.world, pos);
this.addOwnSlots(player); this.addOwnSlots(player);

View file

@ -15,8 +15,8 @@ import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.InputMappings; import net.minecraft.client.util.InputMappings;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;

View file

@ -4,7 +4,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.CraftingInventory; import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.ItemStackHelper; import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.Container;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.item.crafting.RecipeItemHelper; import net.minecraft.item.crafting.RecipeItemHelper;
import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.ItemStackHandler;