diff --git a/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java b/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java index 3cab51c..308c001 100644 --- a/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java +++ b/src/main/java/net/montoyo/wd/block/BlockKeyboardRight.java @@ -5,18 +5,23 @@ package net.montoyo.wd.block; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Material; import net.minecraft.world.phys.AABB; -import net.montoyo.wd.WebDisplays; +import net.minecraft.world.phys.BlockHitResult; import net.montoyo.wd.core.DefaultPeripheral; import net.montoyo.wd.core.IPeripheral; import net.montoyo.wd.entity.TileEntityKeyboard; @@ -24,9 +29,6 @@ import net.montoyo.wd.item.ItemLinker; import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.Vector3i; -import javax.annotation.Nonnull; -import java.util.Random; - public class BlockKeyboardRight extends Block implements IPeripheral { public static final IntegerProperty facing = IntegerProperty.create("facing", 0, 3); @@ -35,76 +37,34 @@ public class BlockKeyboardRight extends Block implements IPeripheral { public BlockKeyboardRight() { super(Properties.of(Material.STONE) .strength(1.5f, 10.f)); + //("keyboard") //fullBlock = false; } @Override - @Nonnull - protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, properties); + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + builder.add(facing); } @Override - public int quantityDropped(Random random) { - return 0; - } - - @Override - public boolean isFullCube(BlockState state) { + public boolean isCollisionShapeFullBlock(BlockState state, BlockGetter level, BlockPos pos) { return false; } - @Override - public boolean isFullBlock(BlockState state) { - return false; - } - - @Override - public boolean isNormalCube(BlockState state, BlockGetter world, BlockPos pos) { - return false; - } - - @Override - public boolean isOpaqueCube(BlockState state) { - return false; - } - - @Override - public boolean doesSideBlockRendering(BlockState state, BlockGetter world, BlockPos pos, EnumFacing face) { - return false; - } - - @Override + /*@Override @Nonnull public AABB getBoundingBox(BlockState state, IBlockAccess source, BlockPos pos) { return KEYBOARD_AABB; - } - - @Override - @Nonnull - public BlockState getStateFromMeta(int meta) { - return getDefaultState().withProperty(facing, meta); - } - - @Override - public int getMetaFromState(BlockState state) { - return state.getValue(facing); - } - - @Override - @Nonnull - public ItemStack getPickBlock(@Nonnull BlockState state, RayTraceResult target, @Nonnull Level world, @Nonnull BlockPos pos, EntityPlayer player) { - return new ItemStack(WebDisplays.INSTANCE.blockPeripheral, 1, 0); - } + }*/ private TileEntityKeyboard getTileEntity(Level world, BlockPos pos) { - for(EnumFacing nf: EnumFacing.HORIZONTALS) { - BlockPos np = pos.add(nf.getDirectionVec()); - IBlockState ns = world.getBlockState(np); + for(Direction nf: Direction.Plane.HORIZONTAL) { + BlockPos np = pos.above(nf.getNormal().getX()); //TODO is X correct? + BlockState ns = world.getBlockState(np); if(ns.getBlock() instanceof BlockPeripheral && ns.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) { - TileEntity te = world.getTileEntity(np); + BlockEntity te = world.getBlockEntity(np); if(te != null && te instanceof TileEntityKeyboard) return (TileEntityKeyboard) te; @@ -121,18 +81,12 @@ public class BlockKeyboardRight extends Block implements IPeripheral { return keyboard != null && keyboard.connect(world, pos, state, scrPos, scrSide); } - @Override - @Nonnull - public EnumPushReaction getMobilityFlag(BlockState state) { - return EnumPushReaction.IGNORE; - } - - public static boolean checkNeighborhood(IBlockAccess world, BlockPos bp, BlockPos ignore) { - for(EnumFacing neighbor: EnumFacing.HORIZONTALS) { - BlockPos np = bp.add(neighbor.getDirectionVec()); + public static boolean checkNeighborhood(Level world, BlockPos bp, BlockPos ignore) { + for(Direction neighbor: Direction.Plane.HORIZONTAL) { + BlockPos np = bp.above(neighbor.getNormal().getX()); //TODO is X correct? if(ignore == null || !np.equals(ignore)) { - IBlockState state = world.getBlockState(np); + BlockState state = world.getBlockState(np); if(state.getBlock() instanceof BlockPeripheral) { if(state.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) @@ -146,47 +100,43 @@ public class BlockKeyboardRight extends Block implements IPeripheral { } public void removeLeftPiece(Level world, BlockPos pos, boolean dropItem) { - for(EnumFacing nf: EnumFacing.HORIZONTALS) { - BlockPos np = pos.add(nf.getDirectionVec()); + for(Direction nf: Direction.Plane.HORIZONTAL) { + BlockPos np = pos.above(nf.getNormal().getX()); //TODO is X correct? BlockState ns = world.getBlockState(np); if(ns.getBlock() instanceof BlockPeripheral && ns.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) { - if(dropItem) - ns.getBlock().dropBlockAsItem(world, np, ns, 0); - - world.setBlockToAir(np); + /* if(dropItem) + if(world instanceof ServerLevel serverWorld) { + // ns.getBlock().getDrops(ns, serverWorld, np,0); + } */ + world.setBlock(np, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL_IMMEDIATE); break; } } } @Override - public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor) { - if(world.isClientSide) + public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos neighbor, boolean isMoving) { + if (world.isClientSide()) return; - if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ() && world.isAirBlock(neighbor)) { + if(neighbor.getX() == pos.getX() && neighbor.getY() == pos.getY() - 1 && neighbor.getZ() == pos.getZ()) { removeLeftPiece(world, pos, true); - world.setBlockToAir(pos); + world.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL_IMMEDIATE); } } @Override - public boolean removedByPlayer(@Nonnull BlockState state, Level world, @Nonnull BlockPos pos, @Nonnull Player ply, boolean willHarvest) { + public boolean onDestroyedByPlayer(BlockState state, Level world, BlockPos pos, Player ply, boolean willHarvest, FluidState fluid) { if(!world.isClientSide) removeLeftPiece(world, pos, !ply.isCreative()); - return super.removedByPlayer(state, world, pos, ply, willHarvest); + return super.onDestroyedByPlayer(state, world, pos, ply, willHarvest, fluid); } - @Override - public void onBlockDestroyedByExplosion(Level world, BlockPos pos, Explosion explosionIn) { - if(!world.isClientSide) - removeLeftPiece(world, pos, true); - } @Override - public void onEntityCollidedWithBlock(Level world, BlockPos pos, BlockState state, Entity entity) { + public void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) { double rpos = (entity.getY() - ((double) pos.getY())) * 16.0; if(!world.isClientSide && rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) { TileEntityKeyboard tek = getTileEntity(world, pos); @@ -197,18 +147,18 @@ public class BlockKeyboardRight extends Block implements IPeripheral { } @Override - public boolean onBlockActivated(Level world, BlockPos pos, BlockState state, Player player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { - if(player.isSneaking()) - return false; + public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + if(player.isShiftKeyDown()) + return InteractionResult.PASS; - if(player.getHeldItem(hand).getItem() instanceof ItemLinker) - return false; + if(player.getItemInHand(hand).getItem() instanceof ItemLinker) + return InteractionResult.PASS; - TileEntityKeyboard tek = getTileEntity(world, pos); + TileEntityKeyboard tek = getTileEntity(level, pos); if(tek != null) - return tek.onRightClick(player, hand, BlockSide.values()[facing.ordinal()]); + return tek.onRightClick(player, hand); - return false; + return InteractionResult.PASS; } } diff --git a/src/main/java/net/montoyo/wd/block/BlockScreen.java b/src/main/java/net/montoyo/wd/block/BlockScreen.java index 0f39b7e..07deff6 100644 --- a/src/main/java/net/montoyo/wd/block/BlockScreen.java +++ b/src/main/java/net/montoyo/wd/block/BlockScreen.java @@ -40,6 +40,7 @@ import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.core.IUpgrade; import net.montoyo.wd.data.SetURLData; import net.montoyo.wd.entity.TileEntityScreen; +import net.montoyo.wd.item.ItemPeripheral; import net.montoyo.wd.item.WDItem; import net.montoyo.wd.utilities.*; @@ -376,7 +377,7 @@ public class BlockScreen extends WDBlockContainer { } @Override - protected ItemBlock createItemBlock() { + protected ItemPeripheral createItemBlock() { return new ItemBlockScreen(this); } diff --git a/src/main/java/net/montoyo/wd/block/WDBlock.java b/src/main/java/net/montoyo/wd/block/WDBlock.java index 4dab4a7..2013e2e 100644 --- a/src/main/java/net/montoyo/wd/block/WDBlock.java +++ b/src/main/java/net/montoyo/wd/block/WDBlock.java @@ -4,25 +4,19 @@ package net.montoyo.wd.block; -import net.minecraft.block.Block; -import net.minecraft.block.material.MapColor; -import net.minecraft.block.material.Material; -import net.minecraft.item.ItemBlock; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; public abstract class WDBlock extends Block { - protected ItemBlock itemBlock; + protected BlockItem itemBlock; - public WDBlock(Material mat, MapColor color) { - super(mat, color); - } - - public WDBlock(Material material) { - super(material); + public WDBlock(Properties properties) { + super(properties); } protected void setName(String name) { - setUnlocalizedName("webdisplays." + name); setRegistryName(name); } @@ -30,12 +24,11 @@ public abstract class WDBlock extends Block { if(itemBlock != null) throw new RuntimeException("WDBlock.makeItemBlock() called twice!"); - itemBlock = new ItemBlock(this); - itemBlock.setUnlocalizedName(getUnlocalizedName()); + itemBlock = new BlockItem(this, new Item.Properties()); itemBlock.setRegistryName(getRegistryName()); } - public ItemBlock getItem() { + public BlockItem getItem() { return itemBlock; } diff --git a/src/main/java/net/montoyo/wd/block/WDBlockContainer.java b/src/main/java/net/montoyo/wd/block/WDBlockContainer.java index 1fa4197..378e2e6 100644 --- a/src/main/java/net/montoyo/wd/block/WDBlockContainer.java +++ b/src/main/java/net/montoyo/wd/block/WDBlockContainer.java @@ -4,38 +4,33 @@ package net.montoyo.wd.block; -import net.minecraft.block.BlockContainer; -import net.minecraft.block.material.MapColor; -import net.minecraft.block.material.Material; -import net.minecraft.item.ItemBlock; +import net.minecraft.core.BlockPos; import net.minecraft.world.item.BlockItem; import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; +import net.montoyo.wd.item.ItemPeripheral; public abstract class WDBlockContainer extends BaseContainerBlockEntity { protected BlockItem itemBlock; - public WDBlockContainer(BlockEntityType type, BlockBehaviour.Properties material, BlockState state) { - super(type, material, state); + public WDBlockContainer(BlockEntityType type, BlockPos blockPos, BlockState state) { + super(type, blockPos, state); } protected void setName(String name) { - setUnlocalizedName("webdisplays." + name); - setRegistryName(name); + // setRegistryName(name); } - protected abstract BlockItem createItemBlock(); + protected abstract ItemPeripheral createItemBlock(); public void makeItemBlock() { if(itemBlock != null) throw new RuntimeException("WDBlockContainer.makeItemBlock() called twice!"); itemBlock = createItemBlock(); - itemBlock.setUnlocalizedName(getUnlocalizedName()); - itemBlock.setRegistryName(getRegistryName()); + itemBlock.setRegistryName(getName().getString()); } public BlockItem getItem() { diff --git a/src/main/java/net/montoyo/wd/client/ClientProxy.java b/src/main/java/net/montoyo/wd/client/ClientProxy.java index 596609a..9ddc76a 100644 --- a/src/main/java/net/montoyo/wd/client/ClientProxy.java +++ b/src/main/java/net/montoyo/wd/client/ClientProxy.java @@ -6,6 +6,7 @@ package net.montoyo.wd.client; import com.mojang.authlib.GameProfile; import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementProgress; import net.minecraft.client.Minecraft; @@ -534,8 +535,8 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer if(tes.isLoaded()) { if(dist2 > WebDisplays.INSTANCE.unloadDistance2) tes.unload(); - else if(WebDisplays.INSTANCE.enableSoundDistance) - tes.updateTrackDistance(dist2, SoundSystemConfig.getMasterGain()); + //else if(WebDisplays.INSTANCE.enableSoundDistance) + // tes.updateTrackDistance(dist2, SoundSystemConfig.getMasterGain()); } else if(dist2 <= WebDisplays.INSTANCE.loadDistance2) tes.load(); } @@ -635,7 +636,7 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer if(ev.getHand() == InteractionHand.OFF_HAND) handSide = handSide.getOpposite(); - renderer.render(ev.getItemStack(), (handSide == HumanoidArm.RIGHT) ? 1.0f : -1.0f, ev.getSwingProgress(), ev.getEquipProgress()); + renderer.render(new PoseStack(), ev.getItemStack(), (handSide == HumanoidArm.RIGHT) ? 1.0f : -1.0f, ev.getSwingProgress(), ev.getEquipProgress()); ev.setCanceled(true); } diff --git a/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java b/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java index 1a6d60c..14ca8a7 100644 --- a/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java +++ b/src/main/java/net/montoyo/wd/client/JSQueryDispatcher.java @@ -6,6 +6,7 @@ package net.montoyo.wd.client; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -18,6 +19,7 @@ import net.montoyo.wd.core.IScreenQueryHandler; import net.montoyo.wd.core.IUpgrade; import net.montoyo.wd.core.JSServerRequest; import net.montoyo.wd.entity.TileEntityScreen; +import net.montoyo.wd.net.Messages; import net.montoyo.wd.net.server.SMessageScreenCtrl; import net.montoyo.wd.utilities.*; @@ -213,7 +215,7 @@ public final class JSQueryDispatcher { ServerQuery ret = new ServerQuery(tes, side, cb); serverQueries.add(ret); - WebDisplays.NET_HANDLER.sendToServer(SMessageScreenCtrl.jsRequest(tes, side, ret.id, type, data)); + Messages.INSTANCE.sendToServer(SMessageScreenCtrl.jsRequest(tes, side, ret.id, type, data)); } private void registerDefaults() { @@ -236,8 +238,8 @@ public final class JSQueryDispatcher { if(x < 0 || x >= scr.size.x || y < 0 || y >= scr.size.y) cb.failure(403, "Out of range"); else { - BlockPos bpos = (new Vector3i(tes.getPos())).addMul(side.right, x).addMul(side.up, y).toBlock(); - int level = tes.getWorld().getBlockState(bpos).getValue(BlockScreen.emitting) ? 0 : tes.getWorld().getRedstonePower(bpos, EnumFacing.VALUES[side.reverse().ordinal()]); + BlockPos bpos = (new Vector3i(tes.getBlockPos())).addMul(side.right, x).addMul(side.up, y).toBlock(); + int level = tes.getLevel().getBlockState(bpos).getValue(BlockScreen.emitting) ? 0 : tes.getLevel().getSignal(bpos, Direction.values()[side.reverse().ordinal()]); cb.success("{\"level\":" + level + "}"); } } else @@ -246,14 +248,14 @@ public final class JSQueryDispatcher { register("GetRedstoneArray", (cb, tes, side, args) -> { if(tes.hasUpgrade(side, DefaultUpgrade.REDSTONE_INPUT)) { - final EnumFacing facing = EnumFacing.VALUES[side.reverse().ordinal()]; + final Direction facing = Direction.values()[side.reverse().ordinal()]; final StringJoiner resp = new StringJoiner(",", "{\"levels\":[", "]}"); tes.forEachScreenBlocks(side, bp -> { - if(tes.getWorld().getBlockState(bp).getValue(BlockScreen.emitting)) + if(tes.getLevel().getBlockState(bp).getValue(BlockScreen.emitting)) resp.add("0"); else - resp.add("" + tes.getWorld().getRedstonePower(bp, facing)); + resp.add("" + tes.getLevel().getSignal(bp, facing)); }); cb.success(resp.toString()); @@ -314,8 +316,8 @@ public final class JSQueryDispatcher { if(x < 0 || x >= scr.size.x || y < 0 || y >= scr.size.y) cb.failure(403, "Out of range"); else { - BlockPos bpos = (new Vector3i(tes.getPos())).addMul(side.right, x).addMul(side.up, y).toBlock(); - boolean e = tes.getWorld().getBlockState(bpos).getValue(BlockScreen.emitting); + BlockPos bpos = (new Vector3i(tes.getBlockPos())).addMul(side.right, x).addMul(side.up, y).toBlock(); + boolean e = tes.getLevel().getBlockState(bpos).getValue(BlockScreen.emitting); cb.success("{\"emitting\":" + (e ? "true" : "false") + "}"); } } else @@ -325,7 +327,7 @@ public final class JSQueryDispatcher { register("GetEmissionArray", (cb, tes, side, args) -> { if(tes.hasUpgrade(side, DefaultUpgrade.REDSTONE_OUTPUT)) { final StringJoiner resp = new StringJoiner(",", "{\"emission\":[", "]}"); - tes.forEachScreenBlocks(side, bp -> resp.add(tes.getWorld().getBlockState(bp).getValue(BlockScreen.emitting) ? "1" : "0")); + tes.forEachScreenBlocks(side, bp -> resp.add(tes.getLevel().getBlockState(bp).getValue(BlockScreen.emitting) ? "1" : "0")); cb.success(resp.toString()); } else cb.failure(403, "Missing upgrade"); @@ -337,7 +339,7 @@ public final class JSQueryDispatcher { return; } - BlockPos bp = tes.getPos(); + BlockPos bp = tes.getBlockPos(); cb.success("{\"x\":" + bp.getX() + ",\"y\":" + bp.getY() + ",\"z\":" + bp.getZ() + ",\"side\":\"" + side + "\"}"); }); diff --git a/src/main/java/net/montoyo/wd/client/gui/GuiRedstoneCtrl.java b/src/main/java/net/montoyo/wd/client/gui/GuiRedstoneCtrl.java index 823a5eb..6d82dfc 100644 --- a/src/main/java/net/montoyo/wd/client/gui/GuiRedstoneCtrl.java +++ b/src/main/java/net/montoyo/wd/client/gui/GuiRedstoneCtrl.java @@ -4,6 +4,8 @@ package net.montoyo.wd.client.gui; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.montoyo.mcef.api.API; @@ -21,7 +23,7 @@ import javax.annotation.Nullable; public class GuiRedstoneCtrl extends WDScreen { - private int dimension; + private ResourceLocation dimension; private Vector3i pos; private String risingEdgeURL; private String fallingEdgeURL; @@ -38,7 +40,8 @@ public class GuiRedstoneCtrl extends WDScreen { public GuiRedstoneCtrl() { } - public GuiRedstoneCtrl(int d, Vector3i p, String r, String f) { + public GuiRedstoneCtrl(ResourceLocation d, Vector3i p, String r, String f) { + super(component); dimension = d; pos = p; risingEdgeURL = r; diff --git a/src/main/java/net/montoyo/wd/client/renderers/ScreenBaker.java b/src/main/java/net/montoyo/wd/client/renderers/ScreenBaker.java index bc3313a..9e66ccf 100644 --- a/src/main/java/net/montoyo/wd/client/renderers/ScreenBaker.java +++ b/src/main/java/net/montoyo/wd/client/renderers/ScreenBaker.java @@ -6,21 +6,14 @@ package net.montoyo.wd.client.renderers; import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.ResourceLocation; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.property.IExtendedBlockState; import net.montoyo.wd.block.BlockScreen; import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.Vector3f; @@ -123,6 +116,11 @@ public class ScreenBaker implements IModelBaker { return true; } + @Override + public boolean usesBlockLight() { + return false; + } + @Override public boolean isCustomRenderer() { return false; diff --git a/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java b/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java index 5e84728..10b43f1 100644 --- a/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java +++ b/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java @@ -6,24 +6,26 @@ package net.montoyo.wd.client.renderers; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.world.phys.AABB; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.client.ClientProxy; import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.utilities.Vector3f; import net.montoyo.wd.utilities.Vector3i; +import org.jetbrains.annotations.NotNull; import static org.lwjgl.opengl.GL11.*; -public class ScreenRenderer extends BlockEntityRenderers { +public class ScreenRenderer implements BlockEntityRenderer { private final Vector3f mid = new Vector3f(); private final Vector3i tmpi = new Vector3i(); private final Vector3f tmpf = new Vector3f(); @Override - public void render(TileEntityScreen te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) { + public void render(TileEntityScreen te, float partialTick, @NotNull PoseStack poseStack, @NotNull MultiBufferSource bufferSource, int packedLight, int packedOverlay) { if(!te.isLoaded()) return; @@ -51,7 +53,7 @@ public class ScreenRenderer extends BlockEntityRenderers { tmpi.addMul(scr.side.up, scr.size.y); tmpf.set(tmpi); - mid.set(x + 0.5, y + 0.5, z + 0.5); + mid.set(tmpf.x + 0.5, tmpi.y + 0.5, tmpi.z + 0.5); mid.addMul(tmpf, 0.5f); tmpf.set(scr.side.left); mid.addMul(tmpf, 0.5f); @@ -190,11 +192,10 @@ public class ScreenRenderer extends BlockEntityRenderers { glDisable(GL_BLEND); } - @Override - public boolean isGlobalRenderer(TileEntityScreen te) { + // @Override + // public boolean isGlobalRenderer(TileEntityScreen te) { //I don't like making it a global renderer for performance reasons, //but Minecraft's AABB-in-view-frustum checking is crappy as hell. - return te.isLoaded(); - } - + // return te.isLoaded(); + // } } diff --git a/src/main/java/net/montoyo/wd/core/CraftComponent.java b/src/main/java/net/montoyo/wd/core/CraftComponent.java index 571c883..a0b1cfe 100644 --- a/src/main/java/net/montoyo/wd/core/CraftComponent.java +++ b/src/main/java/net/montoyo/wd/core/CraftComponent.java @@ -4,10 +4,6 @@ package net.montoyo.wd.core; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.tags.TagKey; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.montoyo.wd.WebDisplays; diff --git a/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java b/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java index 5992df6..b569761 100644 --- a/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java +++ b/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java @@ -4,14 +4,15 @@ package net.montoyo.wd.core; +import net.minecraft.util.StringRepresentable; import net.minecraft.world.level.block.entity.BlockEntity; import net.montoyo.wd.entity.*; -public enum DefaultPeripheral { +public enum DefaultPeripheral implements StringRepresentable { KEYBOARD("keyboard", "Keyboard", TileEntityKeyboard.class), //WITH FACING (< 3) - CC_INTERFACE("ccinterface", "ComputerCraft_Interface", TileEntityCCInterface.class), - OC_INTERFACE("cointerface", "OpenComputers_Interface", TileEntityOCInterface.class), +// CC_INTERFACE("ccinterface", "ComputerCraft_Interface", TileEntityCCInterface.class), +// OC_INTERFACE("cointerface", "OpenComputers_Interface", TileEntityOCInterface.class), REMOTE_CONTROLLER("remotectrl", "Remote_Controller", TileEntityRCtrl.class), //WITHOUT FACING (>= 3) REDSTONE_CONTROLLER("redstonectrl", "Redstone_Controller", TileEntityRedCtrl.class), SERVER("server", "Server", TileEntityServer.class); @@ -51,4 +52,8 @@ public enum DefaultPeripheral { return ret; } + @Override + public String getSerializedName() { + return "DefaultPeripheral"; + } } diff --git a/src/main/java/net/montoyo/wd/data/RedstoneCtrlData.java b/src/main/java/net/montoyo/wd/data/RedstoneCtrlData.java index 2618615..78f96e3 100644 --- a/src/main/java/net/montoyo/wd/data/RedstoneCtrlData.java +++ b/src/main/java/net/montoyo/wd/data/RedstoneCtrlData.java @@ -6,6 +6,7 @@ package net.montoyo.wd.data; import net.minecraft.client.gui.screens.Screen; import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -14,7 +15,7 @@ import net.montoyo.wd.utilities.Vector3i; public class RedstoneCtrlData extends GuiData { - public int dimension; + public ResourceLocation dimension; public Vector3i pos; public String risingEdgeURL; public String fallingEdgeURL; @@ -22,7 +23,7 @@ public class RedstoneCtrlData extends GuiData { public RedstoneCtrlData() { } - public RedstoneCtrlData(int d, BlockPos p, String r, String f) { + public RedstoneCtrlData(ResourceLocation d, BlockPos p, String r, String f) { dimension = d; pos = new Vector3i(p); risingEdgeURL = r; diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityCCInterface.java b/src/main/java/net/montoyo/wd/entity/TileEntityCCInterface.java index c2ce365..3153c53 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityCCInterface.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityCCInterface.java @@ -3,7 +3,7 @@ */ package net.montoyo.wd.entity; - +/* import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.peripheral.IComputerAccess; @@ -80,4 +80,4 @@ public class TileEntityCCInterface extends TileEntityInterfaceBase implements IP return periph == this; } -} +}*/ diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityInterfaceBase.java b/src/main/java/net/montoyo/wd/entity/TileEntityInterfaceBase.java index cbf3b25..7bd3764 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityInterfaceBase.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityInterfaceBase.java @@ -4,8 +4,11 @@ package net.montoyo.wd.entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.core.IComputerArgs; import net.montoyo.wd.core.IUpgrade; @@ -23,6 +26,10 @@ import java.util.Map; public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase { + public TileEntityInterfaceBase(BlockEntityType arg, BlockPos arg2, BlockState arg3) { + super(arg, arg2, arg3); + } + @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface ComputerFunc {} @@ -32,21 +39,22 @@ public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase { private static final Object[] FALSE = new Object[] { false }; @Override - public void readFromNBT(NBTTagCompound tag) { - super.readFromNBT(tag); + public void deserializeNBT(CompoundTag tag) { + super.deserializeNBT(tag); owner = Util.readOwnerFromNBT(tag); } @Override @Nonnull - public NBTTagCompound writeToNBT(NBTTagCompound tag) { - super.writeToNBT(tag); + public CompoundTag serializeNBT() { + CompoundTag tag = new CompoundTag(); + super.serializeNBT(); return Util.writeOwnerToNBT(tag, owner); } - public void setOwner(EntityPlayer ep) { + public void setOwner(Player ep) { owner = new NameUUIDPair(ep.getGameProfile()); - markDirty(); + setChanged(); } @ComputerFunc @@ -392,7 +400,7 @@ public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase { if(isLinked()) { screenPos = null; screenSide = null; - markDirty(); + setChanged(); } return null; diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityKeyboard.java b/src/main/java/net/montoyo/wd/entity/TileEntityKeyboard.java index b15a263..2f48c74 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityKeyboard.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityKeyboard.java @@ -4,11 +4,15 @@ package net.montoyo.wd.entity; -import net.minecraft.entity.Entity; -import net.minecraft.entity.passive.EntityOcelot; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.EnumHand; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.animal.Ocelot; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.data.KeyboardData; @@ -19,30 +23,34 @@ public class TileEntityKeyboard extends TileEntityPeripheralBase { private static final String RANDOM_CHARS = "AZERTYUIOPQSDFGHJKLMWXCVBNazertyuiopqsdfghjklmwxcvbn0123456789"; //Yes I have an AZERTY keyboard, u care? + public TileEntityKeyboard(BlockEntityType arg, BlockPos arg2, BlockState arg3) { + super(arg, arg2, arg3); + } + @Override - public boolean onRightClick(EntityPlayer player, EnumHand hand, BlockSide side) { - if(world.isRemote) - return true; + public InteractionResult onRightClick(Player player, InteractionHand hand) { + if(level.isClientSide) + return InteractionResult.SUCCESS; if(!isScreenChunkLoaded()) { Util.toast(player, "chunkUnloaded"); - return true; + return InteractionResult.SUCCESS; } TileEntityScreen tes = getConnectedScreen(); if(tes == null) { Util.toast(player, "notLinked"); - return true; + return InteractionResult.SUCCESS; } TileEntityScreen.Screen scr = tes.getScreen(screenSide); if((scr.rightsFor(player) & ScreenRights.CLICK) == 0) { Util.toast(player, "restrictions"); - return true; + return InteractionResult.SUCCESS; } - (new KeyboardData(tes, screenSide, pos)).sendTo((EntityPlayerMP) player); - return true; + (new KeyboardData(tes, screenSide, getBlockPos())).sendTo((ServerPlayer) player); + return InteractionResult.SUCCESS; } public void simulateCat(Entity ent) { @@ -53,18 +61,18 @@ public class TileEntityKeyboard extends TileEntityPeripheralBase { TileEntityScreen.Screen scr = tes.getScreen(screenSide); boolean ok; - if(ent instanceof EntityPlayer) - ok = (scr.rightsFor((EntityPlayer) ent) & ScreenRights.CLICK) != 0; + if(ent instanceof Player) + ok = (scr.rightsFor((Player) ent) & ScreenRights.CLICK) != 0; else ok = (scr.otherRights & ScreenRights.CLICK) != 0; if(ok) { char rnd = RANDOM_CHARS.charAt((int) (Math.random() * ((double) RANDOM_CHARS.length()))); - tes.type(screenSide, "t" + rnd, pos); + tes.type(screenSide, "t" + rnd, getBlockPos()); - EntityPlayer owner = world.getPlayerEntityByUUID(scr.owner.uuid); - if(owner != null && owner instanceof EntityPlayerMP && ent instanceof EntityOcelot) - WebDisplays.INSTANCE.criterionKeyboardCat.trigger(((EntityPlayerMP) owner).getAdvancements()); + Player owner = level.getPlayerByUUID(scr.owner.uuid); + if(owner != null && owner instanceof ServerPlayer && ent instanceof Ocelot) + WebDisplays.INSTANCE.criterionKeyboardCat.trigger(((ServerPlayer) owner).getAdvancements()); } } } diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityOCInterface.java b/src/main/java/net/montoyo/wd/entity/TileEntityOCInterface.java index 70f235b..16b83d1 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityOCInterface.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityOCInterface.java @@ -4,6 +4,7 @@ package net.montoyo.wd.entity; +/* import li.cil.oc.api.machine.Arguments; import li.cil.oc.api.machine.Callback; import li.cil.oc.api.machine.Context; @@ -133,4 +134,4 @@ public class TileEntityOCInterface extends TileEntityInterfaceBase implements Si return unlink(new OCArguments(args)); } -} +}*/ diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityPeripheralBase.java b/src/main/java/net/montoyo/wd/entity/TileEntityPeripheralBase.java index e7900d0..b95ca8f 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityPeripheralBase.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityPeripheralBase.java @@ -4,15 +4,17 @@ package net.montoyo.wd.entity; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.LevelChunk; import net.montoyo.wd.core.IPeripheral; import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.Log; @@ -20,19 +22,24 @@ import net.montoyo.wd.utilities.Vector3i; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Objects; -public abstract class TileEntityPeripheralBase extends TileEntity implements IPeripheral { +public abstract class TileEntityPeripheralBase extends BlockEntity implements IPeripheral { protected Vector3i screenPos; protected BlockSide screenSide; - @Override - public void readFromNBT(NBTTagCompound tag) { - super.readFromNBT(tag); + public TileEntityPeripheralBase(BlockEntityType arg, BlockPos arg2, BlockState arg3) { + super(arg, arg2, arg3); + } - if(tag.hasKey("WDScreen", 10)) { - NBTTagCompound scr = tag.getCompoundTag("WDScreen"); - screenPos = new Vector3i(scr.getInteger("X"), scr.getInteger("Y"), scr.getInteger("Z")); + @Override + public void deserializeNBT(CompoundTag tag) { + super.deserializeNBT(tag); + + if(tag.contains("WDScreen", 10)) { + CompoundTag scr = tag.getCompound("WDScreen"); + screenPos = new Vector3i(scr.getInt("X"), scr.getInt("Y"), scr.getInt("Z")); screenSide = BlockSide.values()[scr.getByte("Side")]; } else { screenPos = null; @@ -42,25 +49,26 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe @Override @Nonnull - public NBTTagCompound writeToNBT(NBTTagCompound tag) { - super.writeToNBT(tag); + public CompoundTag serializeNBT() { + CompoundTag tag = new CompoundTag(); + super.serializeNBT(); if(screenPos != null && screenSide != null) { - NBTTagCompound scr = new NBTTagCompound(); - scr.setInteger("X", screenPos.x); - scr.setInteger("Y", screenPos.y); - scr.setInteger("Z", screenPos.z); - scr.setByte("Side", (byte) screenSide.ordinal()); + CompoundTag scr = new CompoundTag(); + scr.putInt("X", screenPos.x); + scr.putInt("Y", screenPos.y); + scr.putInt("Z", screenPos.z); + scr.putByte("Side", (byte) screenSide.ordinal()); - tag.setTag("WDScreen", scr); + tag.put("WDScreen", scr); } return tag; } @Override - public boolean connect(World world_, BlockPos blockPos, IBlockState blockState, Vector3i pos, BlockSide side) { - TileEntity te = world.getTileEntity(pos.toBlock()); + public boolean connect(Level world_, BlockPos blockPos, BlockState blockState, Vector3i pos, BlockSide side) { + BlockEntity te = world_.getBlockEntity(pos.toBlock()); if(te == null || !(te instanceof TileEntityScreen)) { Log.error("TileEntityPeripheralBase.connect(): Tile entity at %s is not a screen!", pos.toString()); return false; @@ -73,7 +81,7 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe screenPos = pos; screenSide = side; - markDirty(); + setChanged(); return true; } @@ -82,10 +90,10 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe } public boolean isScreenChunkLoaded() { - if(screenPos == null || screenSide == null) + if (screenPos == null || screenSide == null) return true; - Chunk chunk = world.getChunkProvider().getLoadedChunk(screenPos.x >> 4, screenPos.z >> 4); + LevelChunk chunk = Objects.requireNonNull(getLevel()).getChunkSource().getChunk(screenPos.x >> 4, screenPos.z >> 4, true); return chunk != null && !chunk.isEmpty(); } @@ -94,11 +102,11 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe if(screenPos == null || screenSide == null) return null; - TileEntity te = world.getTileEntity(screenPos.toBlock()); + BlockEntity te = level.getBlockEntity(screenPos.toBlock()); if(te == null || !(te instanceof TileEntityScreen) || ((TileEntityScreen) te).getScreen(screenSide) == null) { screenPos = null; screenSide = null; - markDirty(); + setChanged(); return null; } @@ -110,7 +118,7 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe if(screenPos == null || screenSide == null) return null; - TileEntity te = world.getTileEntity(screenPos.toBlock()); + BlockEntity te = level.getBlockEntity(screenPos.toBlock()); if(te == null || !(te instanceof TileEntityScreen) || ((TileEntityScreen) te).getScreen(screenSide) == null) return null; @@ -127,8 +135,8 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe return screenSide; } - public boolean onRightClick(EntityPlayer player, EnumHand hand, BlockSide side) { - return false; + public InteractionResult onRightClick(Player player, InteractionHand hand) { + return InteractionResult.PASS; } public void onNeighborChange(Block neighborType, BlockPos neighborPos) { diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityRCtrl.java b/src/main/java/net/montoyo/wd/entity/TileEntityRCtrl.java index da5d149..9f76623 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityRCtrl.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityRCtrl.java @@ -4,9 +4,12 @@ package net.montoyo.wd.entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.EnumHand; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.data.SetURLData; import net.montoyo.wd.utilities.BlockSide; @@ -14,9 +17,13 @@ import net.montoyo.wd.utilities.Util; public class TileEntityRCtrl extends TileEntityPeripheralBase { + public TileEntityRCtrl(BlockEntityType arg, BlockPos arg2, BlockState arg3) { + super(arg, arg2, arg3); + } + @Override - public boolean onRightClick(EntityPlayer player, EnumHand hand, BlockSide side) { - if(world.isRemote) + public boolean onRightClick(Player player, InteractionHand hand, BlockSide side) { + if(level.isClientSide) return true; if(!isScreenChunkLoaded()) { @@ -36,7 +43,7 @@ public class TileEntityRCtrl extends TileEntityPeripheralBase { return true; } - (new SetURLData(screenPos, screenSide, scr.url, pos)).sendTo((EntityPlayerMP) player); + (new SetURLData(screenPos, screenSide, scr.url, getBlockPos())).sendTo((ServerPlayer) player); return true; } diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityRedCtrl.java b/src/main/java/net/montoyo/wd/entity/TileEntityRedCtrl.java index 6c84f21..0531098 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityRedCtrl.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityRedCtrl.java @@ -4,12 +4,14 @@ package net.montoyo.wd.entity; -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.data.RedstoneCtrlData; import net.montoyo.wd.utilities.BlockSide; @@ -23,9 +25,13 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase { private String fallingEdgeURL = ""; private boolean state = false; + public TileEntityRedCtrl(BlockEntityType arg, BlockPos arg2, BlockState arg3) { + super(arg, arg2, arg3); + } + @Override - public void readFromNBT(NBTTagCompound tag) { - super.readFromNBT(tag); + public void deserializeNBT(CompoundTag tag) { + super.deserializeNBT(tag); risingEdgeURL = tag.getString("RisingEdgeURL"); fallingEdgeURL = tag.getString("FallingEdgeURL"); @@ -34,18 +40,19 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase { @Override @Nonnull - public NBTTagCompound writeToNBT(NBTTagCompound tag) { - super.writeToNBT(tag); + public CompoundTag serializeNBT() { + CompoundTag tag = new CompoundTag(); + super.serializeNBT(); - tag.setString("RisingEdgeURL", risingEdgeURL); - tag.setString("FallingEdgeURL", fallingEdgeURL); - tag.setBoolean("Powered", state); + tag.putString("RisingEdgeURL", risingEdgeURL); + tag.putString("FallingEdgeURL", fallingEdgeURL); + tag.putBoolean("Powered", state); return tag; } @Override - public boolean onRightClick(EntityPlayer player, EnumHand hand, BlockSide side) { - if(world.isRemote) + public boolean onRightClick(Player player, InteractionHand hand, BlockSide side) { + if(level.isClientSide) return true; if(!isScreenChunkLoaded()) { @@ -65,13 +72,13 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase { return true; } - (new RedstoneCtrlData(world.provider.getDimension(), pos, risingEdgeURL, fallingEdgeURL)).sendTo((EntityPlayerMP) player); + (new RedstoneCtrlData(level.dimension().location(), getBlockPos(), risingEdgeURL, fallingEdgeURL)).sendTo((ServerPlayer) player); return true; } @Override public void onNeighborChange(Block neighborType, BlockPos neighborPos) { - boolean hasPower = (world.isBlockPowered(pos) || world.isBlockPowered(pos.up())); //Same as dispenser + boolean hasPower = (level.hasNeighborSignal(getBlockPos()) || level.hasNeighborSignal(getBlockPos().above())); //Same as dispenser if(hasPower != state) { state = hasPower; @@ -86,11 +93,11 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase { public void setURLs(String r, String f) { risingEdgeURL = r.trim(); fallingEdgeURL = f.trim(); - markDirty(); + setChanged(); } private void changeURL(String url) { - if(world.isRemote || url.isEmpty()) + if(level.isClientSide || url.isEmpty()) return; if(isScreenChunkLoaded()) { diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java index 59f9f2b..995aa7e 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java @@ -4,7 +4,6 @@ package net.montoyo.wd.entity; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -330,7 +329,7 @@ public class TileEntityScreen extends BlockEntity{ if(level.isClientSide) updateAABB(); else - markDirty(); + setChanged(); return ret; } @@ -356,7 +355,7 @@ public class TileEntityScreen extends BlockEntity{ screens.clear(); if(!level.isClientSide) - markDirty(); + setChanged(); } public void requestData(ServerPlayer ep) { @@ -380,7 +379,7 @@ public class TileEntityScreen extends BlockEntity{ scr.browser.loadURL(url); } else { Messages.INSTANCE.sendTo(CMessageScreenUpdate.setURL(this, side, url), point()); - markDirty(); + setChanged(); } } @@ -412,7 +411,7 @@ public class TileEntityScreen extends BlockEntity{ if(screens.isEmpty()) //No more screens: remove tile entity level.setBlock(getBlockPos(), WebDisplays.INSTANCE.blockScreen.getDefaultInstance().withProperty(BlockScreen.hasTE, false)); else - markDirty(); + setChanged(); } } @@ -440,7 +439,7 @@ public class TileEntityScreen extends BlockEntity{ } } else { Messages.INSTANCE.sendTo(CMessageScreenUpdate.setResolution(this, side, res), point()); - markDirty(); + setChanged(); } } @@ -722,7 +721,7 @@ public class TileEntityScreen extends BlockEntity{ if(!scr.friends.contains(pair)) { scr.friends.add(pair); (new ScreenConfigData(new Vector3i(getBlockPos()), side, scr)).updateOnly().sendTo(point()); - markDirty(); + setChanged(); } } } @@ -738,7 +737,7 @@ public class TileEntityScreen extends BlockEntity{ if(scr.friends.remove(pair)) { checkLaserUserRights(scr); (new ScreenConfigData(new Vector3i(getBlockPos()), side, scr)).updateOnly().sendTo(point()); - markDirty(); + setChanged(); } } } @@ -821,7 +820,7 @@ public class TileEntityScreen extends BlockEntity{ } public void updateUpgrades(BlockSide side, ItemStack[] upgrades) { - if(!world.isRemote) { + if(!level.isClientSide) { Log.error("Tried to call TileEntityScreen.updateUpgrades() from server side..."); return; } @@ -876,7 +875,7 @@ public class TileEntityScreen extends BlockEntity{ Messages.INSTANCE.sendTo(CMessageScreenUpdate.upgrade(this, side), point()); itemAsUpgrade.onInstall(this, side, player, isCopy); playSoundAt(WebDisplays.INSTANCE.soundUpgradeAdd, getBlockPos(), 1.0f, 1.0f); - markDirty(); + setChanged(); return true; } @@ -927,7 +926,7 @@ public class TileEntityScreen extends BlockEntity{ scr.upgrades.remove(idxToRemove); Messages.INSTANCE.sendTo(CMessageScreenUpdate.upgrade(this, side), point()); playSoundAt(WebDisplays.INSTANCE.soundUpgradeDel, getBlockPos(), 1.0f, 1.0f); - markDirty(); + setChanged(); } else Log.warning("Tried to remove non-existing upgrade %s to screen %s at %s", safeName(is), side.toString(), pos.toString()); } @@ -1028,7 +1027,7 @@ public class TileEntityScreen extends BlockEntity{ scr.owner = new NameUUIDPair(newOwner.getGameProfile()); Messages.INSTANCE.sendTo(CMessageScreenUpdate.owner(this, side, scr.owner), point()); checkLaserUserRights(scr); - markDirty(); + setChanged(); } public void setRotation(BlockSide side, Rotation rot) { @@ -1051,7 +1050,7 @@ public class TileEntityScreen extends BlockEntity{ } else { scr.rotation = rot; Messages.INSTANCE.sendTo(CMessageScreenUpdate.rotation(this, side, rot), point()); - markDirty(); + setChanged(); } } @@ -1082,7 +1081,7 @@ public class TileEntityScreen extends BlockEntity{ WebDisplays.PROXY.screenUpdateAutoVolumeInGui(new Vector3i(getBlockPos()), side, av); else { Messages.INSTANCE.sendTo(CMessageScreenUpdate.autoVolume(this, side, av), point()); - markDirty(); + setChanged(); } } diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityServer.java b/src/main/java/net/montoyo/wd/entity/TileEntityServer.java index 29d66b6..214d632 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityServer.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityServer.java @@ -4,10 +4,13 @@ package net.montoyo.wd.entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.data.ServerData; import net.montoyo.wd.utilities.NameUUIDPair; @@ -15,36 +18,41 @@ import net.montoyo.wd.utilities.Util; import javax.annotation.Nonnull; -public class TileEntityServer extends TileEntity { +public class TileEntityServer extends BlockEntity { private NameUUIDPair owner; + public TileEntityServer(BlockEntityType arg, BlockPos arg2, BlockState arg3) { + super(arg, arg2, arg3); + } + @Override - public void readFromNBT(NBTTagCompound tag) { - super.readFromNBT(tag); + public void deserializeNBT(CompoundTag tag) { + super.deserializeNBT(tag); owner = Util.readOwnerFromNBT(tag); } @Override @Nonnull - public NBTTagCompound writeToNBT(NBTTagCompound tag) { - super.writeToNBT(tag); + public CompoundTag serializeNBT() { + CompoundTag tag = new CompoundTag(); + super.serializeNBT(); return Util.writeOwnerToNBT(tag, owner); } - public void setOwner(EntityPlayer ep) { + public void setOwner(Player ep) { owner = new NameUUIDPair(ep.getGameProfile()); - markDirty(); + setChanged(); } - public void onPlayerRightClick(EntityPlayer ply) { - if(world.isRemote) + public void onPlayerRightClick(Player ply) { + if(level.isClientSide) return; if(WebDisplays.INSTANCE.miniservPort == 0) Util.toast(ply, "noMiniserv"); - else if(owner != null && ply instanceof EntityPlayerMP) - (new ServerData(pos, owner)).sendTo((EntityPlayerMP) ply); + else if(owner != null && ply instanceof ServerPlayer) + (new ServerData(getBlockPos(), owner)).sendTo((ServerPlayer) ply); } } diff --git a/src/main/java/net/montoyo/wd/item/ItemCraftComponent.java b/src/main/java/net/montoyo/wd/item/ItemCraftComponent.java index aaaf1e3..23b577b 100644 --- a/src/main/java/net/montoyo/wd/item/ItemCraftComponent.java +++ b/src/main/java/net/montoyo/wd/item/ItemCraftComponent.java @@ -4,48 +4,24 @@ package net.montoyo.wd.item; -import com.mojang.realmsclient.gui.ChatFormatting; -import net.minecraft.client.resources.I18n; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; +import net.minecraft.world.item.ItemStack; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.core.CraftComponent; -import net.montoyo.wd.core.HasAdvancement; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.List; +import org.jetbrains.annotations.NotNull; public class ItemCraftComponent extends ItemMulti implements WDItem { - public ItemCraftComponent() { - super(CraftComponent.class); - setUnlocalizedName("webdisplays.craftcomp"); - setRegistryName("craftcomp"); - setCreativeTab(WebDisplays.CREATIVE_TAB); + public ItemCraftComponent(Properties properties) { + super(CraftComponent.class, properties + //setRegistryName("craftcomp"); + .tab(WebDisplays.CREATIVE_TAB)); //Hide the bad extension card from the creative tab creativeTabItems.clear(CraftComponent.BAD_EXTENSION_CARD.ordinal()); } @Override - public void addInformation(ItemStack is, @Nullable World world, List tt, ITooltipFlag ttFlags) { - if(WebDisplays.INSTANCE.doHardRecipe && is.getMetadata() == CraftComponent.EXTENSION_CARD.ordinal() && WebDisplays.PROXY.hasClientPlayerAdvancement(WebDisplays.ADV_PAD_BREAK) != HasAdvancement.YES) { - tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.extcard.cantcraft1")); - tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.extcard.cantcraft2")); - } else if(is.getMetadata() == CraftComponent.BAD_EXTENSION_CARD.ordinal()) - tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.extcard.bad")); - else - tt.add("" + ChatFormatting.ITALIC + I18n.format("item.webdisplays.craftcomp.name")); - - WDItem.addInformation(tt); + public String getWikiName(@NotNull ItemStack is) { + return is.getItem().getName(is).getString(); } - - @Nullable - @Override - public String getWikiName(@Nonnull ItemStack is) { - return CraftComponent.getWikiName(is.getMetadata()); - } - } diff --git a/src/main/java/net/montoyo/wd/item/ItemLaserPointer.java b/src/main/java/net/montoyo/wd/item/ItemLaserPointer.java index 924f621..0bbcfcd 100644 --- a/src/main/java/net/montoyo/wd/item/ItemLaserPointer.java +++ b/src/main/java/net/montoyo/wd/item/ItemLaserPointer.java @@ -4,35 +4,25 @@ package net.montoyo.wd.item; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.montoyo.wd.WebDisplays; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.List; public class ItemLaserPointer extends Item implements WDItem { - public ItemLaserPointer() { - setUnlocalizedName("webdisplays.laserpointer"); - setRegistryName("laserpointer"); - setMaxStackSize(1); - setCreativeTab(WebDisplays.CREATIVE_TAB); - } - - @Override - public void addInformation(ItemStack is, @Nullable World world, List tt, ITooltipFlag ttFlags) { - WDItem.addInformation(tt); + public ItemLaserPointer(Properties properties) { + super(properties + //setRegistryName("laserpointer") + .stacksTo(1) + .tab(WebDisplays.CREATIVE_TAB)); } @Nullable @Override public String getWikiName(@Nonnull ItemStack is) { - return "Laser_Pointer"; + return is.getItem().getName(is).getString(); } } diff --git a/src/main/java/net/montoyo/wd/item/ItemLinker.java b/src/main/java/net/montoyo/wd/item/ItemLinker.java index f85f0b2..3e7579a 100644 --- a/src/main/java/net/montoyo/wd/item/ItemLinker.java +++ b/src/main/java/net/montoyo/wd/item/ItemLinker.java @@ -4,23 +4,15 @@ package net.montoyo.wd.item; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.resources.I18n; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.world.World; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraft.ChatFormatting; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.block.BlockScreen; import net.montoyo.wd.core.IPeripheral; @@ -33,125 +25,100 @@ import net.montoyo.wd.utilities.Vector3i; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.List; public class ItemLinker extends Item implements WDItem { - public ItemLinker() { - setUnlocalizedName("webdisplays.linker"); - setRegistryName("linker"); - setMaxStackSize(1); - setCreativeTab(WebDisplays.CREATIVE_TAB); + public ItemLinker(Properties properties) { + super(properties + //setRegistryName("linker"); + .stacksTo(1) + .tab(WebDisplays.CREATIVE_TAB)); } @Override - @Nonnull - public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos_, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { - if(world.isRemote) - return EnumActionResult.SUCCESS; + public InteractionResult useOn(UseOnContext context) { + if(context.getLevel().isClientSide()) + return InteractionResult.SUCCESS; - ItemStack stack = player.getHeldItem(hand); - NBTTagCompound tag = stack.getTagCompound(); + ItemStack stack = context.getPlayer().getItemInHand(context.getHand()); + CompoundTag tag = stack.getTag(); if(tag != null) { - if(tag.hasKey("ScreenX") && tag.hasKey("ScreenY") && tag.hasKey("ScreenZ") && tag.hasKey("ScreenSide")) { - IBlockState state = world.getBlockState(pos_); + if(tag.contains("ScreenX") && tag.contains("ScreenY") && tag.contains("ScreenZ") && tag.contains("ScreenSide")) { + BlockState state = context.getLevel().getBlockState(context.getClickedPos()); IPeripheral target; if(state.getBlock() instanceof IPeripheral) target = (IPeripheral) state.getBlock(); else { - TileEntity te = world.getTileEntity(pos_); + BlockEntity te = context.getLevel().getBlockEntity(context.getClickedPos()); if(te == null || !(te instanceof IPeripheral)) { - if(player.isSneaking()) { - Util.toast(player, TextFormatting.GOLD, "linkAbort"); - stack.setTagCompound(null); + if(context.getPlayer().isShiftKeyDown()) { + Util.toast(context.getPlayer(), ChatFormatting.GOLD, "linkAbort"); + stack.setTag(null); } else - Util.toast(player, "peripheral"); + Util.toast(context.getPlayer(), "peripheral"); - return EnumActionResult.SUCCESS; + return InteractionResult.SUCCESS; } target = (IPeripheral) te; } - Vector3i tePos = new Vector3i(tag.getInteger("ScreenX"), tag.getInteger("ScreenY"), tag.getInteger("ScreenZ")); + Vector3i tePos = new Vector3i(tag.getInt("ScreenX"), tag.getInt("ScreenY"), tag.getInt("ScreenZ")); BlockSide scrSide = BlockSide.values()[tag.getByte("ScreenSide")]; - if(target.connect(world, pos_, state, tePos, scrSide)) { - Util.toast(player, TextFormatting.AQUA, "linked"); + if(target.connect(context.getLevel(), context.getClickedPos(), state, tePos, scrSide)) { + Util.toast(context.getPlayer(), ChatFormatting.AQUA, "linked"); - if(player instanceof EntityPlayerMP) - WebDisplays.INSTANCE.criterionLinkPeripheral.trigger(((EntityPlayerMP) player).getAdvancements()); + if(context.getPlayer() instanceof ServerPlayer) + WebDisplays.INSTANCE.criterionLinkPeripheral.trigger(((ServerPlayer) context.getPlayer()).getAdvancements()); } else - Util.toast(player, "linkError"); + Util.toast(context.getPlayer(), "linkError"); - stack.setTagCompound(null); - return EnumActionResult.SUCCESS; + stack.setTag(null); + return InteractionResult.SUCCESS; } } - if(!(world.getBlockState(pos_).getBlock() instanceof BlockScreen)) { - Util.toast(player, "notAScreen"); - return EnumActionResult.SUCCESS; + if(!(context.getLevel().getBlockState(context.getClickedPos()).getBlock() instanceof BlockScreen)) { + Util.toast(context.getPlayer(), "notAScreen"); + return InteractionResult.SUCCESS; } - Vector3i pos = new Vector3i(pos_); - BlockSide side = BlockSide.values()[facing.ordinal()]; - Multiblock.findOrigin(world, pos, side, null); + Vector3i pos = new Vector3i(context.getClickedPos()); + BlockSide side = BlockSide.values()[context.getHorizontalDirection().ordinal()]; + Multiblock.findOrigin(context.getLevel(), pos, side, null); - TileEntity te = world.getTileEntity(pos.toBlock()); + BlockEntity te = context.getLevel().getBlockEntity(pos.toBlock()); if(te == null || !(te instanceof TileEntityScreen)) { - Util.toast(player, "turnOn"); - return EnumActionResult.SUCCESS; + Util.toast(context.getPlayer(), "turnOn"); + return InteractionResult.SUCCESS; } TileEntityScreen.Screen scr = ((TileEntityScreen) te).getScreen(side); if(scr == null) - Util.toast(player, "turnOn"); - else if((scr.rightsFor(player) & ScreenRights.MANAGE_UPGRADES) == 0) - Util.toast(player, "restrictions"); + Util.toast(context.getPlayer(), "turnOn"); + else if((scr.rightsFor(context.getPlayer()) & ScreenRights.MANAGE_UPGRADES) == 0) + Util.toast(context.getPlayer(), "restrictions"); else { - tag = new NBTTagCompound(); - tag.setInteger("ScreenX", pos.x); - tag.setInteger("ScreenY", pos.y); - tag.setInteger("ScreenZ", pos.z); - tag.setByte("ScreenSide", (byte) side.ordinal()); + tag = new CompoundTag(); + tag.putInt("ScreenX", pos.x); + tag.putInt("ScreenY", pos.y); + tag.putInt("ScreenZ", pos.z); + tag.putByte("ScreenSide", (byte) side.ordinal()); - stack.setTagCompound(tag); - Util.toast(player, TextFormatting.AQUA, "screenSet2"); + stack.setTag(tag); + Util.toast(context.getPlayer(), ChatFormatting.AQUA, "screenSet2"); } - return EnumActionResult.SUCCESS; - } - - @SideOnly(Side.CLIENT) - @Override - public void addInformation(ItemStack stack, @Nullable World world, List tt, ITooltipFlag ttFlag) { - NBTTagCompound tag = stack.getTagCompound(); - - if(tag != null) { - if(tag.hasKey("ScreenX") && tag.hasKey("ScreenY") && tag.hasKey("ScreenZ") && tag.hasKey("ScreenSide")) { - BlockSide side = BlockSide.fromInt(tag.getByte("ScreenSide")); - if(side == null) - side = BlockSide.BOTTOM; - - tt.add(I18n.format("webdisplays.linker.selectPeripheral")); - tt.add(I18n.format("webdisplays.linker.posInfo", tag.getInteger("ScreenX"), tag.getInteger("ScreenY"), tag.getInteger("ScreenZ"))); - tt.add(I18n.format("webdisplays.linker.sideInfo", I18n.format("webdisplays.side." + side.toString().toLowerCase()))); - WDItem.addInformation(tt); - return; - } - } - - tt.add(I18n.format("webdisplays.linker.selectScreen")); - WDItem.addInformation(tt); + return InteractionResult.SUCCESS; } @Nullable @Override public String getWikiName(@Nonnull ItemStack is) { - return "Linking_Tool"; + return is.getItem().getName(is).getString(); } } diff --git a/src/main/java/net/montoyo/wd/item/ItemMinePad2.java b/src/main/java/net/montoyo/wd/item/ItemMinePad2.java index 7459a67..79ca039 100644 --- a/src/main/java/net/montoyo/wd/item/ItemMinePad2.java +++ b/src/main/java/net/montoyo/wd/item/ItemMinePad2.java @@ -4,109 +4,95 @@ package net.montoyo.wd.item; -import com.mojang.realmsclient.gui.ChatFormatting; -import net.minecraft.client.resources.I18n; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.init.SoundEvents; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; -import net.minecraft.util.SoundCategory; -import net.minecraft.world.World; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.core.CraftComponent; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.List; import java.util.UUID; public class ItemMinePad2 extends Item implements WDItem { - public ItemMinePad2() { - setUnlocalizedName("webdisplays.minepad"); - setRegistryName("minepad"); - setMaxStackSize(1); - setFull3D(); - setMaxDamage(0); - setCreativeTab(WebDisplays.CREATIVE_TAB); + public ItemMinePad2(Properties properties) { + super(properties + //setRegistryName("minepad"); + .stacksTo(1) + //TODO what is Full3D(); + .defaultDurability(0) + .tab(WebDisplays.CREATIVE_TAB)); } private static String getURL(ItemStack is) { - if(is.getTagCompound() == null || !is.getTagCompound().hasKey("PadURL")) + if(is.getTag() == null || !is.getTag().contains("PadURL")) return WebDisplays.INSTANCE.homePage; else - return is.getTagCompound().getString("PadURL"); + return is.getTag().getString("PadURL"); } @Override @Nonnull - public ActionResult onItemRightClick(World world, EntityPlayer ply, @Nonnull EnumHand hand) { - ItemStack is = ply.getHeldItem(hand); + public InteractionResultHolder use(Level world, Player ply, @Nonnull InteractionHand hand) { + ItemStack is = ply.getItemInHand(hand); boolean ok; - if(ply.isSneaking()) { - if(world.isRemote) + if(ply.isShiftKeyDown()) { + if(world.isClientSide) WebDisplays.PROXY.displaySetPadURLGui(getURL(is)); ok = true; - } else if(is.getTagCompound() != null && is.getTagCompound().hasKey("PadID")) { - if(world.isRemote) - WebDisplays.PROXY.openMinePadGui(is.getTagCompound().getInteger("PadID")); + } else if(is.getTag() != null && is.getTag().contains("PadID")) { + if(world.isClientSide) + WebDisplays.PROXY.openMinePadGui(is.getTag().getInt("PadID")); ok = true; } else ok = false; - return ActionResult.newResult(ok ? EnumActionResult.SUCCESS : EnumActionResult.PASS, is); + return new InteractionResultHolder<>(ok ? InteractionResult.SUCCESS : InteractionResult.PASS, is); } - @Override - public void addInformation(ItemStack is, @Nullable World world, List tt, ITooltipFlag ttFlags) { - if(is.getTagCompound() == null || !is.getTagCompound().hasKey("PadID")) - tt.add("" + ChatFormatting.ITALIC + ChatFormatting.GRAY + I18n.format("webdisplays.minepad.turnon")); - - if(is.getMetadata() > 0) - tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.minepad2.info")); - - WDItem.addInformation(tt); - } @Override - public boolean onEntityItemUpdate(EntityItem ent) { - if(ent.onGround && !ent.world.isRemote) { - NBTTagCompound tag = ent.getItem().getTagCompound(); + public boolean onEntityItemUpdate(ItemStack stack, ItemEntity ent) { + if(ent.isOnGround() && !ent.getLevel().isClientSide) { + CompoundTag tag = ent.getItem().getTag(); - if(tag != null && tag.hasKey("ThrowHeight")) { + if(tag != null && tag.contains("ThrowHeight")) { //Delete it, it touched the ground double height = tag.getDouble("ThrowHeight"); UUID thrower = null; - if(tag.hasKey("ThrowerMSB") && tag.hasKey("ThrowerLSB")) + if(tag.contains("ThrowerMSB") && tag.contains("ThrowerLSB")) thrower = new UUID(tag.getLong("ThrowerMSB"), tag.getLong("ThrowerLSB")); - if(tag.hasKey("PadID") || tag.hasKey("PadURL")) { - tag.removeTag("ThrowerMSB"); - tag.removeTag("ThrowerLSB"); - tag.removeTag("ThrowHeight"); + if(tag.contains("PadID") || tag.contains("PadURL")) { + tag.remove("ThrowerMSB"); + tag.remove("ThrowerLSB"); + tag.remove("ThrowHeight"); } else //We can delete the whole tag - ent.getItem().setTagCompound(null); + ent.getItem().setTag(null); - if(thrower != null && height - ent.posY >= 20.0) { - ent.world.playSound(null, ent.posX, ent.posY, ent.posZ, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.BLOCKS, 4.0f, 1.0f); - ent.world.spawnEntity(new EntityItem(ent.world, ent.posX, ent.posY, ent.posZ, CraftComponent.EXTENSION_CARD.makeItemStack())); - ent.setDead(); + if(thrower != null && height - ent.getBlockY() >= 20.0) { + ent.getLevel().playSound(null, ent.getBlockX(), ent.getBlockY(), ent.getBlockZ(), SoundEvents.GLASS_BREAK, SoundSource.BLOCKS, 4.0f, 1.0f); + ent.getLevel().addFreshEntity(new ItemEntity(ent.getLevel(), ent.getBlockX(), ent.getBlockY(), ent.getBlockZ(), CraftComponent.EXTENSION_CARD.makeItemStack())); + ent.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION); - EntityPlayer ply = ent.world.getPlayerEntityByUUID(thrower); - if(ply != null && ply instanceof EntityPlayerMP) - WebDisplays.INSTANCE.criterionPadBreak.trigger(((EntityPlayerMP) ply).getAdvancements()); + Player ply = ent.getLevel().getPlayerByUUID(thrower); + if(ply != null && ply instanceof ServerPlayer) + WebDisplays.INSTANCE.criterionPadBreak.trigger(((ServerPlayer) ply).getAdvancements()); } } } @@ -114,20 +100,10 @@ public class ItemMinePad2 extends Item implements WDItem { return false; } - @Override - @Nonnull - public String getUnlocalizedName(ItemStack stack) { - String ret = getUnlocalizedName(); - if(stack.getMetadata() > 0) - ret += "2"; - - return ret; - } - @Nullable @Override public String getWikiName(@Nonnull ItemStack is) { - return "Mine_Pad"; + return is.getItem().getName(is).getString(); } } diff --git a/src/main/java/net/montoyo/wd/item/ItemMulti.java b/src/main/java/net/montoyo/wd/item/ItemMulti.java index 067907d..a339bd8 100644 --- a/src/main/java/net/montoyo/wd/item/ItemMulti.java +++ b/src/main/java/net/montoyo/wd/item/ItemMulti.java @@ -24,5 +24,4 @@ public class ItemMulti extends Item { public Enum[] getEnumValues() { return values; } - } diff --git a/src/main/java/net/montoyo/wd/item/ItemOwnershipThief.java b/src/main/java/net/montoyo/wd/item/ItemOwnershipThief.java index 0a90a80..6c62953 100644 --- a/src/main/java/net/montoyo/wd/item/ItemOwnershipThief.java +++ b/src/main/java/net/montoyo/wd/item/ItemOwnershipThief.java @@ -4,128 +4,101 @@ package net.montoyo.wd.item; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.world.World; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraft.ChatFormatting; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.block.entity.BlockEntity; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.block.BlockScreen; import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.utilities.*; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.List; public class ItemOwnershipThief extends Item implements WDItem { - public ItemOwnershipThief() { - setUnlocalizedName("webdisplays.ownerthief"); - setRegistryName("ownerthief"); - setMaxStackSize(1); - setCreativeTab(WebDisplays.CREATIVE_TAB); + public ItemOwnershipThief(Properties properties) { + super(properties + //setRegistryName("ownerthief"); + .stacksTo(1) + .tab(WebDisplays.CREATIVE_TAB)); } @Override - @Nonnull - public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos_, EnumHand hand, EnumFacing side_, float hitX, float hitY, float hitZ) { - if(player.isSneaking()) - return EnumActionResult.PASS; + public @NotNull InteractionResult useOn(UseOnContext context) { + if(context.getPlayer().isShiftKeyDown()) + return InteractionResult.PASS; - if(world.isRemote) - return EnumActionResult.SUCCESS; + if(context.getLevel().isClientSide) + return InteractionResult.SUCCESS; if(WebDisplays.INSTANCE.disableOwnershipThief) { - Util.toast(player, "otDisabled"); - return EnumActionResult.SUCCESS; + Util.toast(context.getPlayer(), "otDisabled"); + return InteractionResult.SUCCESS; } - ItemStack stack = player.getHeldItem(hand); - if(stack.hasTagCompound()) { - NBTTagCompound tag = stack.getTagCompound(); + ItemStack stack = context.getPlayer().getItemInHand(context.getHand()); + if(stack.hasTag()) { + CompoundTag tag = stack.getTag(); - if(tag.hasKey("PosX") && tag.hasKey("PosY") && tag.hasKey("PosZ") && tag.hasKey("Side")) { - BlockPos bp = new BlockPos(tag.getInteger("PosX"), tag.getInteger("PosY"), tag.getInteger("PosZ")); + if(tag.contains("PosX") && tag.contains("PosY") && tag.contains("PosZ") && tag.contains("Side")) { + BlockPos bp = new BlockPos(tag.getInt("PosX"), tag.getInt("PosY"), tag.getInt("PosZ")); BlockSide side = BlockSide.values()[tag.getByte("Side")]; - if(!(world.getBlockState(bp).getBlock() instanceof BlockScreen)) - return EnumActionResult.SUCCESS; + if(!(context.getLevel().getBlockState(bp).getBlock() instanceof BlockScreen)) + return InteractionResult.SUCCESS; - TileEntity te = world.getTileEntity(bp); + BlockEntity te = context.getLevel().getBlockEntity(bp); if(te == null || !(te instanceof TileEntityScreen)) - return EnumActionResult.SUCCESS; + return InteractionResult.SUCCESS; TileEntityScreen tes = (TileEntityScreen) te; TileEntityScreen.Screen scr = tes.getScreen(side); if(scr == null) - return EnumActionResult.SUCCESS; + return InteractionResult.SUCCESS; - Log.warning("Owner of screen at %d %d %d, side %s was changed from %s (UUID %s) to %s (UUID %s)", bp.getX(), bp.getY(), bp.getZ(), side.toString(), scr.owner.name, scr.owner.uuid.toString(), player.getName(), player.getGameProfile().getId().toString()); - player.setHeldItem(hand, ItemStack.EMPTY); - tes.setOwner(side, player); - Util.toast(player, TextFormatting.AQUA, "newOwner"); - return EnumActionResult.SUCCESS; + Log.warning("Owner of screen at %d %d %d, side %s was changed from %s (UUID %s) to %s (UUID %s)", bp.getX(), bp.getY(), bp.getZ(), side.toString(), scr.owner.name, scr.owner.uuid.toString(), context.getPlayer().getName(), context.getPlayer().getGameProfile().getId().toString()); + context.getPlayer().setItemInHand(context.getHand(), ItemStack.EMPTY); + tes.setOwner(side, context.getPlayer()); + Util.toast(context.getPlayer(), ChatFormatting.AQUA, "newOwner"); + return InteractionResult.SUCCESS; } } - if(!(world.getBlockState(pos_).getBlock() instanceof BlockScreen)) - return EnumActionResult.SUCCESS; + if(!(context.getLevel().getBlockState(context.getClickedPos()).getBlock() instanceof BlockScreen)) + return InteractionResult.SUCCESS; - Vector3i pos = new Vector3i(pos_); - BlockSide side = BlockSide.values()[side_.ordinal()]; - Multiblock.findOrigin(world, pos, side, null); + Vector3i pos = new Vector3i(context.getClickedPos()); + BlockSide side = BlockSide.values()[context.getHorizontalDirection().ordinal()]; + Multiblock.findOrigin(context.getLevel(), pos, side, null); - TileEntity te = world.getTileEntity(pos.toBlock()); + BlockEntity te = context.getLevel().getBlockEntity(pos.toBlock()); if(te == null || !(te instanceof TileEntityScreen)) { - Util.toast(player, "turnOn"); - return EnumActionResult.SUCCESS; + Util.toast(context.getPlayer(), "turnOn"); + return InteractionResult.SUCCESS; } if(((TileEntityScreen) te).getScreen(side) == null) - Util.toast(player, "turnOn"); + Util.toast(context.getPlayer(), "turnOn"); else { - NBTTagCompound tag = new NBTTagCompound(); - tag.setInteger("PosX", pos.x); - tag.setInteger("PosY", pos.y); - tag.setInteger("PosZ", pos.z); - tag.setByte("Side", (byte) side.ordinal()); + CompoundTag tag = new CompoundTag(); + tag.putInt("PosX", pos.x); + tag.putInt("PosY", pos.y); + tag.putInt("PosZ", pos.z); + tag.putByte("Side", (byte) side.ordinal()); - stack.setTagCompound(tag); - Util.toast(player, TextFormatting.AQUA, "screenSet"); - Log.warning("Player %s (UUID %s) created an Ownership Thief item for screen at %d %d %d, side %s!", player.getName(), player.getGameProfile().getId().toString(), pos.x, pos.y, pos.z, side.toString()); + stack.setTag(tag); + Util.toast(context.getPlayer(), ChatFormatting.AQUA, "screenSet"); + Log.warning("Player %s (UUID %s) created an Ownership Thief item for screen at %d %d %d, side %s!", context.getPlayer().getName(), context.getPlayer().getGameProfile().getId().toString(), pos.x, pos.y, pos.z, side.toString()); } - return EnumActionResult.SUCCESS; - } - - @SideOnly(Side.CLIENT) - @Override - public void addInformation(ItemStack stack, @Nullable World world, List tt, ITooltipFlag ttFlags) { - if(stack.hasTagCompound()) { - NBTTagCompound tag = stack.getTagCompound(); - - if(tag.hasKey("PosX") && tag.hasKey("PosY") && tag.hasKey("PosZ") && tag.hasKey("Side")) { - tt.add("Screen pos: " + tag.getInteger("PosX") + ", " + tag.getInteger("PosY") + ", " + tag.getInteger("PosZ")); - tt.add("Screen side: " + BlockSide.values()[tag.getByte("Side")].toString()); - WDItem.addInformation(tt); - return; - } - } - - tt.add("" + TextFormatting.RED + "WARNING: Admin tool"); - tt.add("Right click on screen"); - tt.add("and give to new owner."); - WDItem.addInformation(tt); + return InteractionResult.SUCCESS; } @Nullable diff --git a/src/main/java/net/montoyo/wd/item/ItemPeripheral.java b/src/main/java/net/montoyo/wd/item/ItemPeripheral.java index fb02149..3b39aac 100644 --- a/src/main/java/net/montoyo/wd/item/ItemPeripheral.java +++ b/src/main/java/net/montoyo/wd/item/ItemPeripheral.java @@ -4,34 +4,22 @@ package net.montoyo.wd.item; -import com.mojang.realmsclient.gui.ChatFormatting; -import net.minecraft.block.Block; -import net.minecraft.client.resources.I18n; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemMultiTexture; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3i; -import net.minecraft.world.World; -import net.montoyo.wd.WebDisplays; -import net.montoyo.wd.block.BlockKeyboardRight; -import net.montoyo.wd.core.DefaultPeripheral; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.montoyo.wd.core.WDCreativeTab; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.List; -public class ItemPeripheral extends ItemMultiTexture implements WDItem { +public class ItemPeripheral extends Item implements WDItem { - public ItemPeripheral(Block block) { - super(block, block, (is) -> DefaultPeripheral.fromMetadata(is.getMetadata()).getName()); + public ItemPeripheral() { + super(new Properties().tab(WDCreativeTab.TAB_REDSTONE)); } - @Override - public boolean canPlaceBlockOnSide(World world, @Nonnull BlockPos pos_, @Nonnull EnumFacing side, EntityPlayer player, ItemStack stack) { + //TODO what was this! + /*@Override + public boolean canPlaceBlock(Level world, @Nonnull BlockPos pos_, @Nonnull EnumFacing side, EntityPlayer player, ItemStack stack) { if(stack.getMetadata() != 0) //Keyboard return true; @@ -49,28 +37,12 @@ public class ItemPeripheral extends ItemMultiTexture implements WDItem { return true; else return world.isAirBlock(left) && !world.isAirBlock(left.down()) && BlockKeyboardRight.checkNeighborhood(world, left, null); - } - - @Override - public void addInformation(@Nullable ItemStack is, @Nullable World world, @Nullable List tt, @Nullable ITooltipFlag ttFlags) { - super.addInformation(is, world, tt, ttFlags); - - if(is != null && tt != null) { - if(is.getMetadata() == 1 && !WebDisplays.isComputerCraftAvailable()) //CC Interface - tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.message.missingCC")); - else if(is.getMetadata() == 2 && !WebDisplays.isOpenComputersAvailable()) //OC Interface - tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.message.missingOC")); - else if(is.getMetadata() == 11 && WebDisplays.PROXY.isMiniservDisabled()) //Server - tt.add("" + ChatFormatting.RED + I18n.format("webdisplays.message.noMiniserv")); - } - - WDItem.addInformation(tt); - } + } */ @Nullable @Override public String getWikiName(@Nonnull ItemStack is) { - return DefaultPeripheral.fromMetadata(is.getMetadata()).getWikiName(); + return is.getItem().getName(is).getString(); } } diff --git a/src/main/java/net/montoyo/wd/item/ItemScreenConfigurator.java b/src/main/java/net/montoyo/wd/item/ItemScreenConfigurator.java index dfc709d..0d18e92 100644 --- a/src/main/java/net/montoyo/wd/item/ItemScreenConfigurator.java +++ b/src/main/java/net/montoyo/wd/item/ItemScreenConfigurator.java @@ -4,7 +4,12 @@ package net.montoyo.wd.item; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.block.entity.BlockEntity; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.block.BlockScreen; import net.montoyo.wd.data.ScreenConfigData; @@ -13,45 +18,45 @@ import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.Multiblock; import net.montoyo.wd.utilities.Util; import net.montoyo.wd.utilities.Vector3i; +import org.lwjgl.system.CallbackI; import javax.annotation.Nonnull; public class ItemScreenConfigurator extends Item implements WDItem { - public ItemScreenConfigurator() { - setUnlocalizedName("webdisplays.screencfg"); - setRegistryName("screencfg"); - setMaxStackSize(1); - setCreativeTab(WebDisplays.CREATIVE_TAB); + public ItemScreenConfigurator(Properties properties) { + super(properties + //setRegistryName("screencfg"); + .stacksTo(1) + .tab(WebDisplays.CREATIVE_TAB)); } @Override - @Nonnull - public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side_, float hitX, float hitY, float hitZ) { - if(player.isSneaking() || !(world.getBlockState(pos).getBlock() instanceof BlockScreen)) - return EnumActionResult.PASS; + public InteractionResult useOn(UseOnContext context) { + if(context.getPlayer().isShiftKeyDown() || !(context.getLevel().getBlockState(context.getClickedPos()).getBlock() instanceof BlockScreen)) + return InteractionResult.PASS; - if(world.isRemote) - return EnumActionResult.SUCCESS; + if(context.getLevel().isClientSide) + return InteractionResult.SUCCESS; - Vector3i origin = new Vector3i(pos); - BlockSide side = BlockSide.values()[side_.ordinal()]; + Vector3i origin = new Vector3i(context.getClickedPos()); + BlockSide side = BlockSide.values()[context.getHorizontalDirection().ordinal()]; - Multiblock.findOrigin(world, origin, side, null); - TileEntity te = world.getTileEntity(origin.toBlock()); + Multiblock.findOrigin(context.getLevel(), origin, side, null); + BlockEntity te = context.getLevel().getBlockEntity(origin.toBlock()); if(te == null || !(te instanceof TileEntityScreen)) { - Util.toast(player, "turnOn"); - return EnumActionResult.SUCCESS; + Util.toast(context.getPlayer(), "turnOn"); + return InteractionResult.SUCCESS; } TileEntityScreen.Screen scr = ((TileEntityScreen) te).getScreen(side); if(scr == null) - Util.toast(player, "turnOn"); + Util.toast(context.getPlayer(), "turnOn"); else - (new ScreenConfigData(origin, side, scr)).sendTo((EntityPlayerMP) player); + (new ScreenConfigData(origin, side, scr)).sendTo((ServerPlayer) context.getPlayer()); - return EnumActionResult.SUCCESS; + return InteractionResult.SUCCESS; } } diff --git a/src/main/java/net/montoyo/wd/item/ItemUpgrade.java b/src/main/java/net/montoyo/wd/item/ItemUpgrade.java index 8e06499..e6e6cdf 100644 --- a/src/main/java/net/montoyo/wd/item/ItemUpgrade.java +++ b/src/main/java/net/montoyo/wd/item/ItemUpgrade.java @@ -10,6 +10,7 @@ import net.montoyo.wd.core.DefaultUpgrade; import net.montoyo.wd.core.IUpgrade; import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.utilities.BlockSide; +import org.jetbrains.annotations.NotNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -49,4 +50,9 @@ public class ItemUpgrade extends ItemMulti implements IUpgrade, WDItem { else return "webdisplays:" + is; } + + @Override + public String getWikiName(@NotNull ItemStack is) { + return is.getItem().getName(is).getString(); + } } diff --git a/src/main/java/net/montoyo/wd/item/WDItem.java b/src/main/java/net/montoyo/wd/item/WDItem.java index 9ced9b2..d514fa2 100644 --- a/src/main/java/net/montoyo/wd/item/WDItem.java +++ b/src/main/java/net/montoyo/wd/item/WDItem.java @@ -20,6 +20,5 @@ public interface WDItem { tt.add("" + ChatFormatting.GRAY + I18n.get("item.webdisplays.wiki")); } - public String getWikiName(@Nonnull ItemStack is); - + String getWikiName(@Nonnull ItemStack is); }