push a lot of stuff

This commit is contained in:
Mysticpasta1 2022-06-23 02:34:15 -05:00
parent 48bf5bc58f
commit 895ee15c7a
31 changed files with 487 additions and 632 deletions

View File

@ -5,18 +5,23 @@
package net.montoyo.wd.block; package net.montoyo.wd.block;
import net.minecraft.core.BlockPos; 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.Entity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; 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.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; 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.level.material.Material;
import net.minecraft.world.phys.AABB; 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.DefaultPeripheral;
import net.montoyo.wd.core.IPeripheral; import net.montoyo.wd.core.IPeripheral;
import net.montoyo.wd.entity.TileEntityKeyboard; 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.BlockSide;
import net.montoyo.wd.utilities.Vector3i; import net.montoyo.wd.utilities.Vector3i;
import javax.annotation.Nonnull;
import java.util.Random;
public class BlockKeyboardRight extends Block implements IPeripheral { public class BlockKeyboardRight extends Block implements IPeripheral {
public static final IntegerProperty facing = IntegerProperty.create("facing", 0, 3); public static final IntegerProperty facing = IntegerProperty.create("facing", 0, 3);
@ -35,76 +37,34 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
public BlockKeyboardRight() { public BlockKeyboardRight() {
super(Properties.of(Material.STONE) super(Properties.of(Material.STONE)
.strength(1.5f, 10.f)); .strength(1.5f, 10.f));
//("keyboard") //("keyboard")
//fullBlock = false; //fullBlock = false;
} }
@Override @Override
@Nonnull protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
protected BlockStateContainer createBlockState() { builder.add(facing);
return new BlockStateContainer(this, properties);
} }
@Override @Override
public int quantityDropped(Random random) { public boolean isCollisionShapeFullBlock(BlockState state, BlockGetter level, BlockPos pos) {
return 0;
}
@Override
public boolean isFullCube(BlockState state) {
return false; return false;
} }
@Override /*@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
@Nonnull @Nonnull
public AABB getBoundingBox(BlockState state, IBlockAccess source, BlockPos pos) { public AABB getBoundingBox(BlockState state, IBlockAccess source, BlockPos pos) {
return KEYBOARD_AABB; 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) { private TileEntityKeyboard getTileEntity(Level world, BlockPos pos) {
for(EnumFacing nf: EnumFacing.HORIZONTALS) { for(Direction nf: Direction.Plane.HORIZONTAL) {
BlockPos np = pos.add(nf.getDirectionVec()); BlockPos np = pos.above(nf.getNormal().getX()); //TODO is X correct?
IBlockState ns = world.getBlockState(np); BlockState ns = world.getBlockState(np);
if(ns.getBlock() instanceof BlockPeripheral && ns.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) { 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) if(te != null && te instanceof TileEntityKeyboard)
return (TileEntityKeyboard) te; return (TileEntityKeyboard) te;
@ -121,18 +81,12 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
return keyboard != null && keyboard.connect(world, pos, state, scrPos, scrSide); return keyboard != null && keyboard.connect(world, pos, state, scrPos, scrSide);
} }
@Override public static boolean checkNeighborhood(Level world, BlockPos bp, BlockPos ignore) {
@Nonnull for(Direction neighbor: Direction.Plane.HORIZONTAL) {
public EnumPushReaction getMobilityFlag(BlockState state) { BlockPos np = bp.above(neighbor.getNormal().getX()); //TODO is X correct?
return EnumPushReaction.IGNORE;
}
public static boolean checkNeighborhood(IBlockAccess world, BlockPos bp, BlockPos ignore) {
for(EnumFacing neighbor: EnumFacing.HORIZONTALS) {
BlockPos np = bp.add(neighbor.getDirectionVec());
if(ignore == null || !np.equals(ignore)) { if(ignore == null || !np.equals(ignore)) {
IBlockState state = world.getBlockState(np); BlockState state = world.getBlockState(np);
if(state.getBlock() instanceof BlockPeripheral) { if(state.getBlock() instanceof BlockPeripheral) {
if(state.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) 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) { public void removeLeftPiece(Level world, BlockPos pos, boolean dropItem) {
for(EnumFacing nf: EnumFacing.HORIZONTALS) { for(Direction nf: Direction.Plane.HORIZONTAL) {
BlockPos np = pos.add(nf.getDirectionVec()); BlockPos np = pos.above(nf.getNormal().getX()); //TODO is X correct?
BlockState ns = world.getBlockState(np); BlockState ns = world.getBlockState(np);
if(ns.getBlock() instanceof BlockPeripheral && ns.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) { if(ns.getBlock() instanceof BlockPeripheral && ns.getValue(BlockPeripheral.type) == DefaultPeripheral.KEYBOARD) {
if(dropItem) /* if(dropItem)
ns.getBlock().dropBlockAsItem(world, np, ns, 0); if(world instanceof ServerLevel serverWorld) {
// ns.getBlock().getDrops(ns, serverWorld, np,0);
world.setBlockToAir(np); } */
world.setBlock(np, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL_IMMEDIATE);
break; break;
} }
} }
} }
@Override @Override
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block neighborType, BlockPos neighbor) { public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos neighbor, boolean isMoving) {
if(world.isClientSide) if (world.isClientSide())
return; 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); removeLeftPiece(world, pos, true);
world.setBlockToAir(pos); world.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_ALL_IMMEDIATE);
} }
} }
@Override @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) if(!world.isClientSide)
removeLeftPiece(world, pos, !ply.isCreative()); 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 @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; double rpos = (entity.getY() - ((double) pos.getY())) * 16.0;
if(!world.isClientSide && rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) { if(!world.isClientSide && rpos >= 1.0 && rpos <= 2.0 && Math.random() < 0.25) {
TileEntityKeyboard tek = getTileEntity(world, pos); TileEntityKeyboard tek = getTileEntity(world, pos);
@ -197,18 +147,18 @@ public class BlockKeyboardRight extends Block implements IPeripheral {
} }
@Override @Override
public boolean onBlockActivated(Level world, BlockPos pos, BlockState state, Player player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if(player.isSneaking()) if(player.isShiftKeyDown())
return false; return InteractionResult.PASS;
if(player.getHeldItem(hand).getItem() instanceof ItemLinker) if(player.getItemInHand(hand).getItem() instanceof ItemLinker)
return false; return InteractionResult.PASS;
TileEntityKeyboard tek = getTileEntity(world, pos); TileEntityKeyboard tek = getTileEntity(level, pos);
if(tek != null) if(tek != null)
return tek.onRightClick(player, hand, BlockSide.values()[facing.ordinal()]); return tek.onRightClick(player, hand);
return false; return InteractionResult.PASS;
} }
} }

View File

@ -40,6 +40,7 @@ import net.montoyo.wd.core.ScreenRights;
import net.montoyo.wd.core.IUpgrade; import net.montoyo.wd.core.IUpgrade;
import net.montoyo.wd.data.SetURLData; import net.montoyo.wd.data.SetURLData;
import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.entity.TileEntityScreen;
import net.montoyo.wd.item.ItemPeripheral;
import net.montoyo.wd.item.WDItem; import net.montoyo.wd.item.WDItem;
import net.montoyo.wd.utilities.*; import net.montoyo.wd.utilities.*;
@ -376,7 +377,7 @@ public class BlockScreen extends WDBlockContainer {
} }
@Override @Override
protected ItemBlock createItemBlock() { protected ItemPeripheral createItemBlock() {
return new ItemBlockScreen(this); return new ItemBlockScreen(this);
} }

View File

@ -4,25 +4,19 @@
package net.montoyo.wd.block; package net.montoyo.wd.block;
import net.minecraft.block.Block; import net.minecraft.world.item.BlockItem;
import net.minecraft.block.material.MapColor; import net.minecraft.world.item.Item;
import net.minecraft.block.material.Material; import net.minecraft.world.level.block.Block;
import net.minecraft.item.ItemBlock;
public abstract class WDBlock extends Block { public abstract class WDBlock extends Block {
protected ItemBlock itemBlock; protected BlockItem itemBlock;
public WDBlock(Material mat, MapColor color) { public WDBlock(Properties properties) {
super(mat, color); super(properties);
}
public WDBlock(Material material) {
super(material);
} }
protected void setName(String name) { protected void setName(String name) {
setUnlocalizedName("webdisplays." + name);
setRegistryName(name); setRegistryName(name);
} }
@ -30,12 +24,11 @@ public abstract class WDBlock extends Block {
if(itemBlock != null) if(itemBlock != null)
throw new RuntimeException("WDBlock.makeItemBlock() called twice!"); throw new RuntimeException("WDBlock.makeItemBlock() called twice!");
itemBlock = new ItemBlock(this); itemBlock = new BlockItem(this, new Item.Properties());
itemBlock.setUnlocalizedName(getUnlocalizedName());
itemBlock.setRegistryName(getRegistryName()); itemBlock.setRegistryName(getRegistryName());
} }
public ItemBlock getItem() { public BlockItem getItem() {
return itemBlock; return itemBlock;
} }

View File

@ -4,38 +4,33 @@
package net.montoyo.wd.block; package net.montoyo.wd.block;
import net.minecraft.block.BlockContainer; import net.minecraft.core.BlockPos;
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.BlockItem;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType; 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.minecraft.world.level.block.state.BlockState;
import net.montoyo.wd.item.ItemPeripheral;
public abstract class WDBlockContainer extends BaseContainerBlockEntity { public abstract class WDBlockContainer extends BaseContainerBlockEntity {
protected BlockItem itemBlock; protected BlockItem itemBlock;
public WDBlockContainer(BlockEntityType<?> type, BlockBehaviour.Properties material, BlockState state) { public WDBlockContainer(BlockEntityType<?> type, BlockPos blockPos, BlockState state) {
super(type, material, state); super(type, blockPos, state);
} }
protected void setName(String name) { protected void setName(String name) {
setUnlocalizedName("webdisplays." + name); // setRegistryName(name);
setRegistryName(name);
} }
protected abstract BlockItem createItemBlock(); protected abstract ItemPeripheral createItemBlock();
public void makeItemBlock() { public void makeItemBlock() {
if(itemBlock != null) if(itemBlock != null)
throw new RuntimeException("WDBlockContainer.makeItemBlock() called twice!"); throw new RuntimeException("WDBlockContainer.makeItemBlock() called twice!");
itemBlock = createItemBlock(); itemBlock = createItemBlock();
itemBlock.setUnlocalizedName(getUnlocalizedName()); itemBlock.setRegistryName(getName().getString());
itemBlock.setRegistryName(getRegistryName());
} }
public BlockItem getItem() { public BlockItem getItem() {

View File

@ -6,6 +6,7 @@ package net.montoyo.wd.client;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.advancements.Advancement; import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementProgress; import net.minecraft.advancements.AdvancementProgress;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -534,8 +535,8 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
if(tes.isLoaded()) { if(tes.isLoaded()) {
if(dist2 > WebDisplays.INSTANCE.unloadDistance2) if(dist2 > WebDisplays.INSTANCE.unloadDistance2)
tes.unload(); tes.unload();
else if(WebDisplays.INSTANCE.enableSoundDistance) //else if(WebDisplays.INSTANCE.enableSoundDistance)
tes.updateTrackDistance(dist2, SoundSystemConfig.getMasterGain()); // tes.updateTrackDistance(dist2, SoundSystemConfig.getMasterGain());
} else if(dist2 <= WebDisplays.INSTANCE.loadDistance2) } else if(dist2 <= WebDisplays.INSTANCE.loadDistance2)
tes.load(); tes.load();
} }
@ -635,7 +636,7 @@ public class ClientProxy extends SharedProxy implements IDisplayHandler, IJSQuer
if(ev.getHand() == InteractionHand.OFF_HAND) if(ev.getHand() == InteractionHand.OFF_HAND)
handSide = handSide.getOpposite(); 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); ev.setCanceled(true);
} }

View File

@ -6,6 +6,7 @@ package net.montoyo.wd.client;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; 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.IUpgrade;
import net.montoyo.wd.core.JSServerRequest; import net.montoyo.wd.core.JSServerRequest;
import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.entity.TileEntityScreen;
import net.montoyo.wd.net.Messages;
import net.montoyo.wd.net.server.SMessageScreenCtrl; import net.montoyo.wd.net.server.SMessageScreenCtrl;
import net.montoyo.wd.utilities.*; import net.montoyo.wd.utilities.*;
@ -213,7 +215,7 @@ public final class JSQueryDispatcher {
ServerQuery ret = new ServerQuery(tes, side, cb); ServerQuery ret = new ServerQuery(tes, side, cb);
serverQueries.add(ret); 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() { private void registerDefaults() {
@ -236,8 +238,8 @@ public final class JSQueryDispatcher {
if(x < 0 || x >= scr.size.x || y < 0 || y >= scr.size.y) if(x < 0 || x >= scr.size.x || y < 0 || y >= scr.size.y)
cb.failure(403, "Out of range"); cb.failure(403, "Out of range");
else { else {
BlockPos bpos = (new Vector3i(tes.getPos())).addMul(side.right, x).addMul(side.up, y).toBlock(); BlockPos bpos = (new Vector3i(tes.getBlockPos())).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()]); int level = tes.getLevel().getBlockState(bpos).getValue(BlockScreen.emitting) ? 0 : tes.getLevel().getSignal(bpos, Direction.values()[side.reverse().ordinal()]);
cb.success("{\"level\":" + level + "}"); cb.success("{\"level\":" + level + "}");
} }
} else } else
@ -246,14 +248,14 @@ public final class JSQueryDispatcher {
register("GetRedstoneArray", (cb, tes, side, args) -> { register("GetRedstoneArray", (cb, tes, side, args) -> {
if(tes.hasUpgrade(side, DefaultUpgrade.REDSTONE_INPUT)) { 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\":[", "]}"); final StringJoiner resp = new StringJoiner(",", "{\"levels\":[", "]}");
tes.forEachScreenBlocks(side, bp -> { tes.forEachScreenBlocks(side, bp -> {
if(tes.getWorld().getBlockState(bp).getValue(BlockScreen.emitting)) if(tes.getLevel().getBlockState(bp).getValue(BlockScreen.emitting))
resp.add("0"); resp.add("0");
else else
resp.add("" + tes.getWorld().getRedstonePower(bp, facing)); resp.add("" + tes.getLevel().getSignal(bp, facing));
}); });
cb.success(resp.toString()); 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) if(x < 0 || x >= scr.size.x || y < 0 || y >= scr.size.y)
cb.failure(403, "Out of range"); cb.failure(403, "Out of range");
else { else {
BlockPos bpos = (new Vector3i(tes.getPos())).addMul(side.right, x).addMul(side.up, y).toBlock(); BlockPos bpos = (new Vector3i(tes.getBlockPos())).addMul(side.right, x).addMul(side.up, y).toBlock();
boolean e = tes.getWorld().getBlockState(bpos).getValue(BlockScreen.emitting); boolean e = tes.getLevel().getBlockState(bpos).getValue(BlockScreen.emitting);
cb.success("{\"emitting\":" + (e ? "true" : "false") + "}"); cb.success("{\"emitting\":" + (e ? "true" : "false") + "}");
} }
} else } else
@ -325,7 +327,7 @@ public final class JSQueryDispatcher {
register("GetEmissionArray", (cb, tes, side, args) -> { register("GetEmissionArray", (cb, tes, side, args) -> {
if(tes.hasUpgrade(side, DefaultUpgrade.REDSTONE_OUTPUT)) { if(tes.hasUpgrade(side, DefaultUpgrade.REDSTONE_OUTPUT)) {
final StringJoiner resp = new StringJoiner(",", "{\"emission\":[", "]}"); 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()); cb.success(resp.toString());
} else } else
cb.failure(403, "Missing upgrade"); cb.failure(403, "Missing upgrade");
@ -337,7 +339,7 @@ public final class JSQueryDispatcher {
return; return;
} }
BlockPos bp = tes.getPos(); BlockPos bp = tes.getBlockPos();
cb.success("{\"x\":" + bp.getX() + ",\"y\":" + bp.getY() + ",\"z\":" + bp.getZ() + ",\"side\":\"" + side + "\"}"); cb.success("{\"x\":" + bp.getX() + ",\"y\":" + bp.getY() + ",\"z\":" + bp.getZ() + ",\"side\":\"" + side + "\"}");
}); });

View File

@ -4,6 +4,8 @@
package net.montoyo.wd.client.gui; 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.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.montoyo.mcef.api.API; import net.montoyo.mcef.api.API;
@ -21,7 +23,7 @@ import javax.annotation.Nullable;
public class GuiRedstoneCtrl extends WDScreen { public class GuiRedstoneCtrl extends WDScreen {
private int dimension; private ResourceLocation dimension;
private Vector3i pos; private Vector3i pos;
private String risingEdgeURL; private String risingEdgeURL;
private String fallingEdgeURL; private String fallingEdgeURL;
@ -38,7 +40,8 @@ public class GuiRedstoneCtrl extends WDScreen {
public GuiRedstoneCtrl() { 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; dimension = d;
pos = p; pos = p;
risingEdgeURL = r; risingEdgeURL = r;

View File

@ -6,21 +6,14 @@ package net.montoyo.wd.client.renderers;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.vertex.DefaultVertexFormat; 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.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.client.renderer.block.model.ItemOverrideList;
import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; 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.core.Direction;
import net.minecraft.resources.ResourceLocation; 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.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.montoyo.wd.block.BlockScreen; import net.montoyo.wd.block.BlockScreen;
import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Vector3f; import net.montoyo.wd.utilities.Vector3f;
@ -123,6 +116,11 @@ public class ScreenBaker implements IModelBaker {
return true; return true;
} }
@Override
public boolean usesBlockLight() {
return false;
}
@Override @Override
public boolean isCustomRenderer() { public boolean isCustomRenderer() {
return false; return false;

View File

@ -6,24 +6,26 @@ package net.montoyo.wd.client.renderers;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*; 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.minecraft.world.phys.AABB;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.client.ClientProxy; import net.montoyo.wd.client.ClientProxy;
import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.entity.TileEntityScreen;
import net.montoyo.wd.utilities.Vector3f; import net.montoyo.wd.utilities.Vector3f;
import net.montoyo.wd.utilities.Vector3i; import net.montoyo.wd.utilities.Vector3i;
import org.jetbrains.annotations.NotNull;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
public class ScreenRenderer extends BlockEntityRenderers<TileEntityScreen> { public class ScreenRenderer implements BlockEntityRenderer<TileEntityScreen> {
private final Vector3f mid = new Vector3f(); private final Vector3f mid = new Vector3f();
private final Vector3i tmpi = new Vector3i(); private final Vector3i tmpi = new Vector3i();
private final Vector3f tmpf = new Vector3f(); private final Vector3f tmpf = new Vector3f();
@Override @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()) if(!te.isLoaded())
return; return;
@ -51,7 +53,7 @@ public class ScreenRenderer extends BlockEntityRenderers<TileEntityScreen> {
tmpi.addMul(scr.side.up, scr.size.y); tmpi.addMul(scr.side.up, scr.size.y);
tmpf.set(tmpi); 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); mid.addMul(tmpf, 0.5f);
tmpf.set(scr.side.left); tmpf.set(scr.side.left);
mid.addMul(tmpf, 0.5f); mid.addMul(tmpf, 0.5f);
@ -190,11 +192,10 @@ public class ScreenRenderer extends BlockEntityRenderers<TileEntityScreen> {
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
@Override // @Override
public boolean isGlobalRenderer(TileEntityScreen te) { // public boolean isGlobalRenderer(TileEntityScreen te) {
//I don't like making it a global renderer for performance reasons, //I don't like making it a global renderer for performance reasons,
//but Minecraft's AABB-in-view-frustum checking is crappy as hell. //but Minecraft's AABB-in-view-frustum checking is crappy as hell.
return te.isLoaded(); // return te.isLoaded();
} // }
} }

View File

@ -4,10 +4,6 @@
package net.montoyo.wd.core; 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.minecraft.world.item.ItemStack;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;

View File

@ -4,14 +4,15 @@
package net.montoyo.wd.core; package net.montoyo.wd.core;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.montoyo.wd.entity.*; import net.montoyo.wd.entity.*;
public enum DefaultPeripheral { public enum DefaultPeripheral implements StringRepresentable {
KEYBOARD("keyboard", "Keyboard", TileEntityKeyboard.class), //WITH FACING (< 3) KEYBOARD("keyboard", "Keyboard", TileEntityKeyboard.class), //WITH FACING (< 3)
CC_INTERFACE("ccinterface", "ComputerCraft_Interface", TileEntityCCInterface.class), // CC_INTERFACE("ccinterface", "ComputerCraft_Interface", TileEntityCCInterface.class),
OC_INTERFACE("cointerface", "OpenComputers_Interface", TileEntityOCInterface.class), // OC_INTERFACE("cointerface", "OpenComputers_Interface", TileEntityOCInterface.class),
REMOTE_CONTROLLER("remotectrl", "Remote_Controller", TileEntityRCtrl.class), //WITHOUT FACING (>= 3) REMOTE_CONTROLLER("remotectrl", "Remote_Controller", TileEntityRCtrl.class), //WITHOUT FACING (>= 3)
REDSTONE_CONTROLLER("redstonectrl", "Redstone_Controller", TileEntityRedCtrl.class), REDSTONE_CONTROLLER("redstonectrl", "Redstone_Controller", TileEntityRedCtrl.class),
SERVER("server", "Server", TileEntityServer.class); SERVER("server", "Server", TileEntityServer.class);
@ -51,4 +52,8 @@ public enum DefaultPeripheral {
return ret; return ret;
} }
@Override
public String getSerializedName() {
return "DefaultPeripheral";
}
} }

View File

@ -6,6 +6,7 @@ package net.montoyo.wd.data;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -14,7 +15,7 @@ import net.montoyo.wd.utilities.Vector3i;
public class RedstoneCtrlData extends GuiData { public class RedstoneCtrlData extends GuiData {
public int dimension; public ResourceLocation dimension;
public Vector3i pos; public Vector3i pos;
public String risingEdgeURL; public String risingEdgeURL;
public String fallingEdgeURL; public String fallingEdgeURL;
@ -22,7 +23,7 @@ public class RedstoneCtrlData extends GuiData {
public RedstoneCtrlData() { public RedstoneCtrlData() {
} }
public RedstoneCtrlData(int d, BlockPos p, String r, String f) { public RedstoneCtrlData(ResourceLocation d, BlockPos p, String r, String f) {
dimension = d; dimension = d;
pos = new Vector3i(p); pos = new Vector3i(p);
risingEdgeURL = r; risingEdgeURL = r;

View File

@ -3,7 +3,7 @@
*/ */
package net.montoyo.wd.entity; package net.montoyo.wd.entity;
/*
import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IComputerAccess;
@ -80,4 +80,4 @@ public class TileEntityCCInterface extends TileEntityInterfaceBase implements IP
return periph == this; return periph == this;
} }
} }*/

View File

@ -4,8 +4,11 @@
package net.montoyo.wd.entity; package net.montoyo.wd.entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.NBTTagCompound; 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.WebDisplays;
import net.montoyo.wd.core.IComputerArgs; import net.montoyo.wd.core.IComputerArgs;
import net.montoyo.wd.core.IUpgrade; import net.montoyo.wd.core.IUpgrade;
@ -23,6 +26,10 @@ import java.util.Map;
public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase { public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase {
public TileEntityInterfaceBase(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) {
super(arg, arg2, arg3);
}
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface ComputerFunc {} public @interface ComputerFunc {}
@ -32,21 +39,22 @@ public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase {
private static final Object[] FALSE = new Object[] { false }; private static final Object[] FALSE = new Object[] { false };
@Override @Override
public void readFromNBT(NBTTagCompound tag) { public void deserializeNBT(CompoundTag tag) {
super.readFromNBT(tag); super.deserializeNBT(tag);
owner = Util.readOwnerFromNBT(tag); owner = Util.readOwnerFromNBT(tag);
} }
@Override @Override
@Nonnull @Nonnull
public NBTTagCompound writeToNBT(NBTTagCompound tag) { public CompoundTag serializeNBT() {
super.writeToNBT(tag); CompoundTag tag = new CompoundTag();
super.serializeNBT();
return Util.writeOwnerToNBT(tag, owner); return Util.writeOwnerToNBT(tag, owner);
} }
public void setOwner(EntityPlayer ep) { public void setOwner(Player ep) {
owner = new NameUUIDPair(ep.getGameProfile()); owner = new NameUUIDPair(ep.getGameProfile());
markDirty(); setChanged();
} }
@ComputerFunc @ComputerFunc
@ -392,7 +400,7 @@ public abstract class TileEntityInterfaceBase extends TileEntityPeripheralBase {
if(isLinked()) { if(isLinked()) {
screenPos = null; screenPos = null;
screenSide = null; screenSide = null;
markDirty(); setChanged();
} }
return null; return null;

View File

@ -4,11 +4,15 @@
package net.montoyo.wd.entity; package net.montoyo.wd.entity;
import net.minecraft.entity.Entity; import net.minecraft.core.BlockPos;
import net.minecraft.entity.passive.EntityOcelot; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.InteractionHand;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.world.InteractionResult;
import net.minecraft.util.EnumHand; 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.WebDisplays;
import net.montoyo.wd.core.ScreenRights; import net.montoyo.wd.core.ScreenRights;
import net.montoyo.wd.data.KeyboardData; 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? 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 @Override
public boolean onRightClick(EntityPlayer player, EnumHand hand, BlockSide side) { public InteractionResult onRightClick(Player player, InteractionHand hand) {
if(world.isRemote) if(level.isClientSide)
return true; return InteractionResult.SUCCESS;
if(!isScreenChunkLoaded()) { if(!isScreenChunkLoaded()) {
Util.toast(player, "chunkUnloaded"); Util.toast(player, "chunkUnloaded");
return true; return InteractionResult.SUCCESS;
} }
TileEntityScreen tes = getConnectedScreen(); TileEntityScreen tes = getConnectedScreen();
if(tes == null) { if(tes == null) {
Util.toast(player, "notLinked"); Util.toast(player, "notLinked");
return true; return InteractionResult.SUCCESS;
} }
TileEntityScreen.Screen scr = tes.getScreen(screenSide); TileEntityScreen.Screen scr = tes.getScreen(screenSide);
if((scr.rightsFor(player) & ScreenRights.CLICK) == 0) { if((scr.rightsFor(player) & ScreenRights.CLICK) == 0) {
Util.toast(player, "restrictions"); Util.toast(player, "restrictions");
return true; return InteractionResult.SUCCESS;
} }
(new KeyboardData(tes, screenSide, pos)).sendTo((EntityPlayerMP) player); (new KeyboardData(tes, screenSide, getBlockPos())).sendTo((ServerPlayer) player);
return true; return InteractionResult.SUCCESS;
} }
public void simulateCat(Entity ent) { public void simulateCat(Entity ent) {
@ -53,18 +61,18 @@ public class TileEntityKeyboard extends TileEntityPeripheralBase {
TileEntityScreen.Screen scr = tes.getScreen(screenSide); TileEntityScreen.Screen scr = tes.getScreen(screenSide);
boolean ok; boolean ok;
if(ent instanceof EntityPlayer) if(ent instanceof Player)
ok = (scr.rightsFor((EntityPlayer) ent) & ScreenRights.CLICK) != 0; ok = (scr.rightsFor((Player) ent) & ScreenRights.CLICK) != 0;
else else
ok = (scr.otherRights & ScreenRights.CLICK) != 0; ok = (scr.otherRights & ScreenRights.CLICK) != 0;
if(ok) { if(ok) {
char rnd = RANDOM_CHARS.charAt((int) (Math.random() * ((double) RANDOM_CHARS.length()))); 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); Player owner = level.getPlayerByUUID(scr.owner.uuid);
if(owner != null && owner instanceof EntityPlayerMP && ent instanceof EntityOcelot) if(owner != null && owner instanceof ServerPlayer && ent instanceof Ocelot)
WebDisplays.INSTANCE.criterionKeyboardCat.trigger(((EntityPlayerMP) owner).getAdvancements()); WebDisplays.INSTANCE.criterionKeyboardCat.trigger(((ServerPlayer) owner).getAdvancements());
} }
} }
} }

View File

@ -4,6 +4,7 @@
package net.montoyo.wd.entity; package net.montoyo.wd.entity;
/*
import li.cil.oc.api.machine.Arguments; import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback; import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context; import li.cil.oc.api.machine.Context;
@ -133,4 +134,4 @@ public class TileEntityOCInterface extends TileEntityInterfaceBase implements Si
return unlink(new OCArguments(args)); return unlink(new OCArguments(args));
} }
} }*/

View File

@ -4,15 +4,17 @@
package net.montoyo.wd.entity; package net.montoyo.wd.entity;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.CompoundTag;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.InteractionHand;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.InteractionResult;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.util.EnumHand; import net.minecraft.world.level.Level;
import net.minecraft.util.math.BlockPos; import net.minecraft.world.level.block.Block;
import net.minecraft.world.World; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.chunk.Chunk; 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.core.IPeripheral;
import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.BlockSide;
import net.montoyo.wd.utilities.Log; import net.montoyo.wd.utilities.Log;
@ -20,19 +22,24 @@ import net.montoyo.wd.utilities.Vector3i;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; 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 Vector3i screenPos;
protected BlockSide screenSide; protected BlockSide screenSide;
@Override public TileEntityPeripheralBase(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) {
public void readFromNBT(NBTTagCompound tag) { super(arg, arg2, arg3);
super.readFromNBT(tag); }
if(tag.hasKey("WDScreen", 10)) { @Override
NBTTagCompound scr = tag.getCompoundTag("WDScreen"); public void deserializeNBT(CompoundTag tag) {
screenPos = new Vector3i(scr.getInteger("X"), scr.getInteger("Y"), scr.getInteger("Z")); 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")]; screenSide = BlockSide.values()[scr.getByte("Side")];
} else { } else {
screenPos = null; screenPos = null;
@ -42,25 +49,26 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe
@Override @Override
@Nonnull @Nonnull
public NBTTagCompound writeToNBT(NBTTagCompound tag) { public CompoundTag serializeNBT() {
super.writeToNBT(tag); CompoundTag tag = new CompoundTag();
super.serializeNBT();
if(screenPos != null && screenSide != null) { if(screenPos != null && screenSide != null) {
NBTTagCompound scr = new NBTTagCompound(); CompoundTag scr = new CompoundTag();
scr.setInteger("X", screenPos.x); scr.putInt("X", screenPos.x);
scr.setInteger("Y", screenPos.y); scr.putInt("Y", screenPos.y);
scr.setInteger("Z", screenPos.z); scr.putInt("Z", screenPos.z);
scr.setByte("Side", (byte) screenSide.ordinal()); scr.putByte("Side", (byte) screenSide.ordinal());
tag.setTag("WDScreen", scr); tag.put("WDScreen", scr);
} }
return tag; return tag;
} }
@Override @Override
public boolean connect(World world_, BlockPos blockPos, IBlockState blockState, Vector3i pos, BlockSide side) { public boolean connect(Level world_, BlockPos blockPos, BlockState blockState, Vector3i pos, BlockSide side) {
TileEntity te = world.getTileEntity(pos.toBlock()); BlockEntity te = world_.getBlockEntity(pos.toBlock());
if(te == null || !(te instanceof TileEntityScreen)) { if(te == null || !(te instanceof TileEntityScreen)) {
Log.error("TileEntityPeripheralBase.connect(): Tile entity at %s is not a screen!", pos.toString()); Log.error("TileEntityPeripheralBase.connect(): Tile entity at %s is not a screen!", pos.toString());
return false; return false;
@ -73,7 +81,7 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe
screenPos = pos; screenPos = pos;
screenSide = side; screenSide = side;
markDirty(); setChanged();
return true; return true;
} }
@ -82,10 +90,10 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe
} }
public boolean isScreenChunkLoaded() { public boolean isScreenChunkLoaded() {
if(screenPos == null || screenSide == null) if (screenPos == null || screenSide == null)
return true; 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(); return chunk != null && !chunk.isEmpty();
} }
@ -94,11 +102,11 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe
if(screenPos == null || screenSide == null) if(screenPos == null || screenSide == null)
return 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) { if(te == null || !(te instanceof TileEntityScreen) || ((TileEntityScreen) te).getScreen(screenSide) == null) {
screenPos = null; screenPos = null;
screenSide = null; screenSide = null;
markDirty(); setChanged();
return null; return null;
} }
@ -110,7 +118,7 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe
if(screenPos == null || screenSide == null) if(screenPos == null || screenSide == null)
return 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) if(te == null || !(te instanceof TileEntityScreen) || ((TileEntityScreen) te).getScreen(screenSide) == null)
return null; return null;
@ -127,8 +135,8 @@ public abstract class TileEntityPeripheralBase extends TileEntity implements IPe
return screenSide; return screenSide;
} }
public boolean onRightClick(EntityPlayer player, EnumHand hand, BlockSide side) { public InteractionResult onRightClick(Player player, InteractionHand hand) {
return false; return InteractionResult.PASS;
} }
public void onNeighborChange(Block neighborType, BlockPos neighborPos) { public void onNeighborChange(Block neighborType, BlockPos neighborPos) {

View File

@ -4,9 +4,12 @@
package net.montoyo.wd.entity; package net.montoyo.wd.entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.core.BlockPos;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.EnumHand; 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.core.ScreenRights;
import net.montoyo.wd.data.SetURLData; import net.montoyo.wd.data.SetURLData;
import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.BlockSide;
@ -14,9 +17,13 @@ import net.montoyo.wd.utilities.Util;
public class TileEntityRCtrl extends TileEntityPeripheralBase { public class TileEntityRCtrl extends TileEntityPeripheralBase {
public TileEntityRCtrl(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) {
super(arg, arg2, arg3);
}
@Override @Override
public boolean onRightClick(EntityPlayer player, EnumHand hand, BlockSide side) { public boolean onRightClick(Player player, InteractionHand hand, BlockSide side) {
if(world.isRemote) if(level.isClientSide)
return true; return true;
if(!isScreenChunkLoaded()) { if(!isScreenChunkLoaded()) {
@ -36,7 +43,7 @@ public class TileEntityRCtrl extends TileEntityPeripheralBase {
return true; return true;
} }
(new SetURLData(screenPos, screenSide, scr.url, pos)).sendTo((EntityPlayerMP) player); (new SetURLData(screenPos, screenSide, scr.url, getBlockPos())).sendTo((ServerPlayer) player);
return true; return true;
} }

View File

@ -4,12 +4,14 @@
package net.montoyo.wd.entity; package net.montoyo.wd.entity;
import net.minecraft.block.Block; import net.minecraft.core.BlockPos;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.CompoundTag;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.InteractionHand;
import net.minecraft.util.EnumHand; import net.minecraft.world.entity.player.Player;
import net.minecraft.util.math.BlockPos; 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.core.ScreenRights;
import net.montoyo.wd.data.RedstoneCtrlData; import net.montoyo.wd.data.RedstoneCtrlData;
import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.BlockSide;
@ -23,9 +25,13 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase {
private String fallingEdgeURL = ""; private String fallingEdgeURL = "";
private boolean state = false; private boolean state = false;
public TileEntityRedCtrl(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) {
super(arg, arg2, arg3);
}
@Override @Override
public void readFromNBT(NBTTagCompound tag) { public void deserializeNBT(CompoundTag tag) {
super.readFromNBT(tag); super.deserializeNBT(tag);
risingEdgeURL = tag.getString("RisingEdgeURL"); risingEdgeURL = tag.getString("RisingEdgeURL");
fallingEdgeURL = tag.getString("FallingEdgeURL"); fallingEdgeURL = tag.getString("FallingEdgeURL");
@ -34,18 +40,19 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase {
@Override @Override
@Nonnull @Nonnull
public NBTTagCompound writeToNBT(NBTTagCompound tag) { public CompoundTag serializeNBT() {
super.writeToNBT(tag); CompoundTag tag = new CompoundTag();
super.serializeNBT();
tag.setString("RisingEdgeURL", risingEdgeURL); tag.putString("RisingEdgeURL", risingEdgeURL);
tag.setString("FallingEdgeURL", fallingEdgeURL); tag.putString("FallingEdgeURL", fallingEdgeURL);
tag.setBoolean("Powered", state); tag.putBoolean("Powered", state);
return tag; return tag;
} }
@Override @Override
public boolean onRightClick(EntityPlayer player, EnumHand hand, BlockSide side) { public boolean onRightClick(Player player, InteractionHand hand, BlockSide side) {
if(world.isRemote) if(level.isClientSide)
return true; return true;
if(!isScreenChunkLoaded()) { if(!isScreenChunkLoaded()) {
@ -65,13 +72,13 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase {
return true; 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; return true;
} }
@Override @Override
public void onNeighborChange(Block neighborType, BlockPos neighborPos) { 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) { if(hasPower != state) {
state = hasPower; state = hasPower;
@ -86,11 +93,11 @@ public class TileEntityRedCtrl extends TileEntityPeripheralBase {
public void setURLs(String r, String f) { public void setURLs(String r, String f) {
risingEdgeURL = r.trim(); risingEdgeURL = r.trim();
fallingEdgeURL = f.trim(); fallingEdgeURL = f.trim();
markDirty(); setChanged();
} }
private void changeURL(String url) { private void changeURL(String url) {
if(world.isRemote || url.isEmpty()) if(level.isClientSide || url.isEmpty())
return; return;
if(isScreenChunkLoaded()) { if(isScreenChunkLoaded()) {

View File

@ -4,7 +4,6 @@
package net.montoyo.wd.entity; package net.montoyo.wd.entity;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -330,7 +329,7 @@ public class TileEntityScreen extends BlockEntity{
if(level.isClientSide) if(level.isClientSide)
updateAABB(); updateAABB();
else else
markDirty(); setChanged();
return ret; return ret;
} }
@ -356,7 +355,7 @@ public class TileEntityScreen extends BlockEntity{
screens.clear(); screens.clear();
if(!level.isClientSide) if(!level.isClientSide)
markDirty(); setChanged();
} }
public void requestData(ServerPlayer ep) { public void requestData(ServerPlayer ep) {
@ -380,7 +379,7 @@ public class TileEntityScreen extends BlockEntity{
scr.browser.loadURL(url); scr.browser.loadURL(url);
} else { } else {
Messages.INSTANCE.sendTo(CMessageScreenUpdate.setURL(this, side, url), point()); 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 if(screens.isEmpty()) //No more screens: remove tile entity
level.setBlock(getBlockPos(), WebDisplays.INSTANCE.blockScreen.getDefaultInstance().withProperty(BlockScreen.hasTE, false)); level.setBlock(getBlockPos(), WebDisplays.INSTANCE.blockScreen.getDefaultInstance().withProperty(BlockScreen.hasTE, false));
else else
markDirty(); setChanged();
} }
} }
@ -440,7 +439,7 @@ public class TileEntityScreen extends BlockEntity{
} }
} else { } else {
Messages.INSTANCE.sendTo(CMessageScreenUpdate.setResolution(this, side, res), point()); 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)) { if(!scr.friends.contains(pair)) {
scr.friends.add(pair); scr.friends.add(pair);
(new ScreenConfigData(new Vector3i(getBlockPos()), side, scr)).updateOnly().sendTo(point()); (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)) { if(scr.friends.remove(pair)) {
checkLaserUserRights(scr); checkLaserUserRights(scr);
(new ScreenConfigData(new Vector3i(getBlockPos()), side, scr)).updateOnly().sendTo(point()); (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) { public void updateUpgrades(BlockSide side, ItemStack[] upgrades) {
if(!world.isRemote) { if(!level.isClientSide) {
Log.error("Tried to call TileEntityScreen.updateUpgrades() from server side..."); Log.error("Tried to call TileEntityScreen.updateUpgrades() from server side...");
return; return;
} }
@ -876,7 +875,7 @@ public class TileEntityScreen extends BlockEntity{
Messages.INSTANCE.sendTo(CMessageScreenUpdate.upgrade(this, side), point()); Messages.INSTANCE.sendTo(CMessageScreenUpdate.upgrade(this, side), point());
itemAsUpgrade.onInstall(this, side, player, isCopy); itemAsUpgrade.onInstall(this, side, player, isCopy);
playSoundAt(WebDisplays.INSTANCE.soundUpgradeAdd, getBlockPos(), 1.0f, 1.0f); playSoundAt(WebDisplays.INSTANCE.soundUpgradeAdd, getBlockPos(), 1.0f, 1.0f);
markDirty(); setChanged();
return true; return true;
} }
@ -927,7 +926,7 @@ public class TileEntityScreen extends BlockEntity{
scr.upgrades.remove(idxToRemove); scr.upgrades.remove(idxToRemove);
Messages.INSTANCE.sendTo(CMessageScreenUpdate.upgrade(this, side), point()); Messages.INSTANCE.sendTo(CMessageScreenUpdate.upgrade(this, side), point());
playSoundAt(WebDisplays.INSTANCE.soundUpgradeDel, getBlockPos(), 1.0f, 1.0f); playSoundAt(WebDisplays.INSTANCE.soundUpgradeDel, getBlockPos(), 1.0f, 1.0f);
markDirty(); setChanged();
} else } else
Log.warning("Tried to remove non-existing upgrade %s to screen %s at %s", safeName(is), side.toString(), pos.toString()); 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()); scr.owner = new NameUUIDPair(newOwner.getGameProfile());
Messages.INSTANCE.sendTo(CMessageScreenUpdate.owner(this, side, scr.owner), point()); Messages.INSTANCE.sendTo(CMessageScreenUpdate.owner(this, side, scr.owner), point());
checkLaserUserRights(scr); checkLaserUserRights(scr);
markDirty(); setChanged();
} }
public void setRotation(BlockSide side, Rotation rot) { public void setRotation(BlockSide side, Rotation rot) {
@ -1051,7 +1050,7 @@ public class TileEntityScreen extends BlockEntity{
} else { } else {
scr.rotation = rot; scr.rotation = rot;
Messages.INSTANCE.sendTo(CMessageScreenUpdate.rotation(this, side, rot), point()); 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); WebDisplays.PROXY.screenUpdateAutoVolumeInGui(new Vector3i(getBlockPos()), side, av);
else { else {
Messages.INSTANCE.sendTo(CMessageScreenUpdate.autoVolume(this, side, av), point()); Messages.INSTANCE.sendTo(CMessageScreenUpdate.autoVolume(this, side, av), point());
markDirty(); setChanged();
} }
} }

View File

@ -4,10 +4,13 @@
package net.montoyo.wd.entity; package net.montoyo.wd.entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.core.BlockPos;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tileentity.TileEntity; 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.WebDisplays;
import net.montoyo.wd.data.ServerData; import net.montoyo.wd.data.ServerData;
import net.montoyo.wd.utilities.NameUUIDPair; import net.montoyo.wd.utilities.NameUUIDPair;
@ -15,36 +18,41 @@ import net.montoyo.wd.utilities.Util;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public class TileEntityServer extends TileEntity { public class TileEntityServer extends BlockEntity {
private NameUUIDPair owner; private NameUUIDPair owner;
public TileEntityServer(BlockEntityType<?> arg, BlockPos arg2, BlockState arg3) {
super(arg, arg2, arg3);
}
@Override @Override
public void readFromNBT(NBTTagCompound tag) { public void deserializeNBT(CompoundTag tag) {
super.readFromNBT(tag); super.deserializeNBT(tag);
owner = Util.readOwnerFromNBT(tag); owner = Util.readOwnerFromNBT(tag);
} }
@Override @Override
@Nonnull @Nonnull
public NBTTagCompound writeToNBT(NBTTagCompound tag) { public CompoundTag serializeNBT() {
super.writeToNBT(tag); CompoundTag tag = new CompoundTag();
super.serializeNBT();
return Util.writeOwnerToNBT(tag, owner); return Util.writeOwnerToNBT(tag, owner);
} }
public void setOwner(EntityPlayer ep) { public void setOwner(Player ep) {
owner = new NameUUIDPair(ep.getGameProfile()); owner = new NameUUIDPair(ep.getGameProfile());
markDirty(); setChanged();
} }
public void onPlayerRightClick(EntityPlayer ply) { public void onPlayerRightClick(Player ply) {
if(world.isRemote) if(level.isClientSide)
return; return;
if(WebDisplays.INSTANCE.miniservPort == 0) if(WebDisplays.INSTANCE.miniservPort == 0)
Util.toast(ply, "noMiniserv"); Util.toast(ply, "noMiniserv");
else if(owner != null && ply instanceof EntityPlayerMP) else if(owner != null && ply instanceof ServerPlayer)
(new ServerData(pos, owner)).sendTo((EntityPlayerMP) ply); (new ServerData(getBlockPos(), owner)).sendTo((ServerPlayer) ply);
} }
} }

View File

@ -4,48 +4,24 @@
package net.montoyo.wd.item; package net.montoyo.wd.item;
import com.mojang.realmsclient.gui.ChatFormatting; import net.minecraft.world.item.ItemStack;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.core.CraftComponent; import net.montoyo.wd.core.CraftComponent;
import net.montoyo.wd.core.HasAdvancement; import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ItemCraftComponent extends ItemMulti implements WDItem { public class ItemCraftComponent extends ItemMulti implements WDItem {
public ItemCraftComponent() { public ItemCraftComponent(Properties properties) {
super(CraftComponent.class); super(CraftComponent.class, properties
setUnlocalizedName("webdisplays.craftcomp"); //setRegistryName("craftcomp");
setRegistryName("craftcomp"); .tab(WebDisplays.CREATIVE_TAB));
setCreativeTab(WebDisplays.CREATIVE_TAB);
//Hide the bad extension card from the creative tab //Hide the bad extension card from the creative tab
creativeTabItems.clear(CraftComponent.BAD_EXTENSION_CARD.ordinal()); creativeTabItems.clear(CraftComponent.BAD_EXTENSION_CARD.ordinal());
} }
@Override @Override
public void addInformation(ItemStack is, @Nullable World world, List<String> tt, ITooltipFlag ttFlags) { public String getWikiName(@NotNull ItemStack is) {
if(WebDisplays.INSTANCE.doHardRecipe && is.getMetadata() == CraftComponent.EXTENSION_CARD.ordinal() && WebDisplays.PROXY.hasClientPlayerAdvancement(WebDisplays.ADV_PAD_BREAK) != HasAdvancement.YES) { return is.getItem().getName(is).getString();
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);
} }
@Nullable
@Override
public String getWikiName(@Nonnull ItemStack is) {
return CraftComponent.getWikiName(is.getMetadata());
}
} }

View File

@ -4,35 +4,25 @@
package net.montoyo.wd.item; 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.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
public class ItemLaserPointer extends Item implements WDItem { public class ItemLaserPointer extends Item implements WDItem {
public ItemLaserPointer() { public ItemLaserPointer(Properties properties) {
setUnlocalizedName("webdisplays.laserpointer"); super(properties
setRegistryName("laserpointer"); //setRegistryName("laserpointer")
setMaxStackSize(1); .stacksTo(1)
setCreativeTab(WebDisplays.CREATIVE_TAB); .tab(WebDisplays.CREATIVE_TAB));
}
@Override
public void addInformation(ItemStack is, @Nullable World world, List<String> tt, ITooltipFlag ttFlags) {
WDItem.addInformation(tt);
} }
@Nullable @Nullable
@Override @Override
public String getWikiName(@Nonnull ItemStack is) { public String getWikiName(@Nonnull ItemStack is) {
return "Laser_Pointer"; return is.getItem().getName(is).getString();
} }
} }

View File

@ -4,23 +4,15 @@
package net.montoyo.wd.item; package net.montoyo.wd.item;
import net.minecraft.block.state.IBlockState; import net.minecraft.ChatFormatting;
import net.minecraft.client.resources.I18n; import net.minecraft.nbt.CompoundTag;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.InteractionResult;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.world.item.Item;
import net.minecraft.item.Item; import net.minecraft.world.item.ItemStack;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.state.BlockState;
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.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.block.BlockScreen; import net.montoyo.wd.block.BlockScreen;
import net.montoyo.wd.core.IPeripheral; import net.montoyo.wd.core.IPeripheral;
@ -33,125 +25,100 @@ import net.montoyo.wd.utilities.Vector3i;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
public class ItemLinker extends Item implements WDItem { public class ItemLinker extends Item implements WDItem {
public ItemLinker() { public ItemLinker(Properties properties) {
setUnlocalizedName("webdisplays.linker"); super(properties
setRegistryName("linker"); //setRegistryName("linker");
setMaxStackSize(1); .stacksTo(1)
setCreativeTab(WebDisplays.CREATIVE_TAB); .tab(WebDisplays.CREATIVE_TAB));
} }
@Override @Override
@Nonnull public InteractionResult useOn(UseOnContext context) {
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos_, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if(context.getLevel().isClientSide())
if(world.isRemote) return InteractionResult.SUCCESS;
return EnumActionResult.SUCCESS;
ItemStack stack = player.getHeldItem(hand); ItemStack stack = context.getPlayer().getItemInHand(context.getHand());
NBTTagCompound tag = stack.getTagCompound(); CompoundTag tag = stack.getTag();
if(tag != null) { if(tag != null) {
if(tag.hasKey("ScreenX") && tag.hasKey("ScreenY") && tag.hasKey("ScreenZ") && tag.hasKey("ScreenSide")) { if(tag.contains("ScreenX") && tag.contains("ScreenY") && tag.contains("ScreenZ") && tag.contains("ScreenSide")) {
IBlockState state = world.getBlockState(pos_); BlockState state = context.getLevel().getBlockState(context.getClickedPos());
IPeripheral target; IPeripheral target;
if(state.getBlock() instanceof IPeripheral) if(state.getBlock() instanceof IPeripheral)
target = (IPeripheral) state.getBlock(); target = (IPeripheral) state.getBlock();
else { else {
TileEntity te = world.getTileEntity(pos_); BlockEntity te = context.getLevel().getBlockEntity(context.getClickedPos());
if(te == null || !(te instanceof IPeripheral)) { if(te == null || !(te instanceof IPeripheral)) {
if(player.isSneaking()) { if(context.getPlayer().isShiftKeyDown()) {
Util.toast(player, TextFormatting.GOLD, "linkAbort"); Util.toast(context.getPlayer(), ChatFormatting.GOLD, "linkAbort");
stack.setTagCompound(null); stack.setTag(null);
} else } else
Util.toast(player, "peripheral"); Util.toast(context.getPlayer(), "peripheral");
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
target = (IPeripheral) te; 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")]; BlockSide scrSide = BlockSide.values()[tag.getByte("ScreenSide")];
if(target.connect(world, pos_, state, tePos, scrSide)) { if(target.connect(context.getLevel(), context.getClickedPos(), state, tePos, scrSide)) {
Util.toast(player, TextFormatting.AQUA, "linked"); Util.toast(context.getPlayer(), ChatFormatting.AQUA, "linked");
if(player instanceof EntityPlayerMP) if(context.getPlayer() instanceof ServerPlayer)
WebDisplays.INSTANCE.criterionLinkPeripheral.trigger(((EntityPlayerMP) player).getAdvancements()); WebDisplays.INSTANCE.criterionLinkPeripheral.trigger(((ServerPlayer) context.getPlayer()).getAdvancements());
} else } else
Util.toast(player, "linkError"); Util.toast(context.getPlayer(), "linkError");
stack.setTagCompound(null); stack.setTag(null);
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
} }
if(!(world.getBlockState(pos_).getBlock() instanceof BlockScreen)) { if(!(context.getLevel().getBlockState(context.getClickedPos()).getBlock() instanceof BlockScreen)) {
Util.toast(player, "notAScreen"); Util.toast(context.getPlayer(), "notAScreen");
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
Vector3i pos = new Vector3i(pos_); Vector3i pos = new Vector3i(context.getClickedPos());
BlockSide side = BlockSide.values()[facing.ordinal()]; BlockSide side = BlockSide.values()[context.getHorizontalDirection().ordinal()];
Multiblock.findOrigin(world, pos, side, null); 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)) { if(te == null || !(te instanceof TileEntityScreen)) {
Util.toast(player, "turnOn"); Util.toast(context.getPlayer(), "turnOn");
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
TileEntityScreen.Screen scr = ((TileEntityScreen) te).getScreen(side); TileEntityScreen.Screen scr = ((TileEntityScreen) te).getScreen(side);
if(scr == null) if(scr == null)
Util.toast(player, "turnOn"); Util.toast(context.getPlayer(), "turnOn");
else if((scr.rightsFor(player) & ScreenRights.MANAGE_UPGRADES) == 0) else if((scr.rightsFor(context.getPlayer()) & ScreenRights.MANAGE_UPGRADES) == 0)
Util.toast(player, "restrictions"); Util.toast(context.getPlayer(), "restrictions");
else { else {
tag = new NBTTagCompound(); tag = new CompoundTag();
tag.setInteger("ScreenX", pos.x); tag.putInt("ScreenX", pos.x);
tag.setInteger("ScreenY", pos.y); tag.putInt("ScreenY", pos.y);
tag.setInteger("ScreenZ", pos.z); tag.putInt("ScreenZ", pos.z);
tag.setByte("ScreenSide", (byte) side.ordinal()); tag.putByte("ScreenSide", (byte) side.ordinal());
stack.setTagCompound(tag); stack.setTag(tag);
Util.toast(player, TextFormatting.AQUA, "screenSet2"); Util.toast(context.getPlayer(), ChatFormatting.AQUA, "screenSet2");
} }
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
}
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, @Nullable World world, List<String> 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);
} }
@Nullable @Nullable
@Override @Override
public String getWikiName(@Nonnull ItemStack is) { public String getWikiName(@Nonnull ItemStack is) {
return "Linking_Tool"; return is.getItem().getName(is).getString();
} }
} }

View File

@ -4,109 +4,95 @@
package net.montoyo.wd.item; package net.montoyo.wd.item;
import com.mojang.realmsclient.gui.ChatFormatting; import net.minecraft.nbt.CompoundTag;
import net.minecraft.client.resources.I18n; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.sounds.SoundEvents;
import net.minecraft.entity.item.EntityItem; import net.minecraft.sounds.SoundSource;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.InteractionHand;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.world.InteractionResult;
import net.minecraft.init.SoundEvents; import net.minecraft.world.InteractionResultHolder;
import net.minecraft.item.Item; import net.minecraft.world.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.entity.player.Player;
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.world.item.Item; 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.WebDisplays;
import net.montoyo.wd.core.CraftComponent; import net.montoyo.wd.core.CraftComponent;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class ItemMinePad2 extends Item implements WDItem { public class ItemMinePad2 extends Item implements WDItem {
public ItemMinePad2() { public ItemMinePad2(Properties properties) {
setUnlocalizedName("webdisplays.minepad"); super(properties
setRegistryName("minepad"); //setRegistryName("minepad");
setMaxStackSize(1); .stacksTo(1)
setFull3D(); //TODO what is Full3D();
setMaxDamage(0); .defaultDurability(0)
setCreativeTab(WebDisplays.CREATIVE_TAB); .tab(WebDisplays.CREATIVE_TAB));
} }
private static String getURL(ItemStack is) { 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; return WebDisplays.INSTANCE.homePage;
else else
return is.getTagCompound().getString("PadURL"); return is.getTag().getString("PadURL");
} }
@Override @Override
@Nonnull @Nonnull
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer ply, @Nonnull EnumHand hand) { public InteractionResultHolder<ItemStack> use(Level world, Player ply, @Nonnull InteractionHand hand) {
ItemStack is = ply.getHeldItem(hand); ItemStack is = ply.getItemInHand(hand);
boolean ok; boolean ok;
if(ply.isSneaking()) { if(ply.isShiftKeyDown()) {
if(world.isRemote) if(world.isClientSide)
WebDisplays.PROXY.displaySetPadURLGui(getURL(is)); WebDisplays.PROXY.displaySetPadURLGui(getURL(is));
ok = true; ok = true;
} else if(is.getTagCompound() != null && is.getTagCompound().hasKey("PadID")) { } else if(is.getTag() != null && is.getTag().contains("PadID")) {
if(world.isRemote) if(world.isClientSide)
WebDisplays.PROXY.openMinePadGui(is.getTagCompound().getInteger("PadID")); WebDisplays.PROXY.openMinePadGui(is.getTag().getInt("PadID"));
ok = true; ok = true;
} else } else
ok = false; 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<String> 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 @Override
public boolean onEntityItemUpdate(EntityItem ent) { public boolean onEntityItemUpdate(ItemStack stack, ItemEntity ent) {
if(ent.onGround && !ent.world.isRemote) { if(ent.isOnGround() && !ent.getLevel().isClientSide) {
NBTTagCompound tag = ent.getItem().getTagCompound(); CompoundTag tag = ent.getItem().getTag();
if(tag != null && tag.hasKey("ThrowHeight")) { if(tag != null && tag.contains("ThrowHeight")) {
//Delete it, it touched the ground //Delete it, it touched the ground
double height = tag.getDouble("ThrowHeight"); double height = tag.getDouble("ThrowHeight");
UUID thrower = null; 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")); thrower = new UUID(tag.getLong("ThrowerMSB"), tag.getLong("ThrowerLSB"));
if(tag.hasKey("PadID") || tag.hasKey("PadURL")) { if(tag.contains("PadID") || tag.contains("PadURL")) {
tag.removeTag("ThrowerMSB"); tag.remove("ThrowerMSB");
tag.removeTag("ThrowerLSB"); tag.remove("ThrowerLSB");
tag.removeTag("ThrowHeight"); tag.remove("ThrowHeight");
} else //We can delete the whole tag } else //We can delete the whole tag
ent.getItem().setTagCompound(null); ent.getItem().setTag(null);
if(thrower != null && height - ent.posY >= 20.0) { if(thrower != null && height - ent.getBlockY() >= 20.0) {
ent.world.playSound(null, ent.posX, ent.posY, ent.posZ, SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.BLOCKS, 4.0f, 1.0f); ent.getLevel().playSound(null, ent.getBlockX(), ent.getBlockY(), ent.getBlockZ(), SoundEvents.GLASS_BREAK, SoundSource.BLOCKS, 4.0f, 1.0f);
ent.world.spawnEntity(new EntityItem(ent.world, ent.posX, ent.posY, ent.posZ, CraftComponent.EXTENSION_CARD.makeItemStack())); ent.getLevel().addFreshEntity(new ItemEntity(ent.getLevel(), ent.getBlockX(), ent.getBlockY(), ent.getBlockZ(), CraftComponent.EXTENSION_CARD.makeItemStack()));
ent.setDead(); ent.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
EntityPlayer ply = ent.world.getPlayerEntityByUUID(thrower); Player ply = ent.getLevel().getPlayerByUUID(thrower);
if(ply != null && ply instanceof EntityPlayerMP) if(ply != null && ply instanceof ServerPlayer)
WebDisplays.INSTANCE.criterionPadBreak.trigger(((EntityPlayerMP) ply).getAdvancements()); WebDisplays.INSTANCE.criterionPadBreak.trigger(((ServerPlayer) ply).getAdvancements());
} }
} }
} }
@ -114,20 +100,10 @@ public class ItemMinePad2 extends Item implements WDItem {
return false; return false;
} }
@Override
@Nonnull
public String getUnlocalizedName(ItemStack stack) {
String ret = getUnlocalizedName();
if(stack.getMetadata() > 0)
ret += "2";
return ret;
}
@Nullable @Nullable
@Override @Override
public String getWikiName(@Nonnull ItemStack is) { public String getWikiName(@Nonnull ItemStack is) {
return "Mine_Pad"; return is.getItem().getName(is).getString();
} }
} }

View File

@ -24,5 +24,4 @@ public class ItemMulti extends Item {
public Enum[] getEnumValues() { public Enum[] getEnumValues() {
return values; return values;
} }
} }

View File

@ -4,128 +4,101 @@
package net.montoyo.wd.item; package net.montoyo.wd.item;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.ChatFormatting;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.core.BlockPos;
import net.minecraft.item.Item; import net.minecraft.nbt.CompoundTag;
import net.minecraft.item.ItemStack; import net.minecraft.world.InteractionResult;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.item.Item;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.EnumActionResult; import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.util.EnumFacing; import net.minecraft.world.level.block.entity.BlockEntity;
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.montoyo.wd.WebDisplays; import net.montoyo.wd.WebDisplays;
import net.montoyo.wd.block.BlockScreen; import net.montoyo.wd.block.BlockScreen;
import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.entity.TileEntityScreen;
import net.montoyo.wd.utilities.*; import net.montoyo.wd.utilities.*;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List;
public class ItemOwnershipThief extends Item implements WDItem { public class ItemOwnershipThief extends Item implements WDItem {
public ItemOwnershipThief() { public ItemOwnershipThief(Properties properties) {
setUnlocalizedName("webdisplays.ownerthief"); super(properties
setRegistryName("ownerthief"); //setRegistryName("ownerthief");
setMaxStackSize(1); .stacksTo(1)
setCreativeTab(WebDisplays.CREATIVE_TAB); .tab(WebDisplays.CREATIVE_TAB));
} }
@Override @Override
@Nonnull public @NotNull InteractionResult useOn(UseOnContext context) {
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos_, EnumHand hand, EnumFacing side_, float hitX, float hitY, float hitZ) { if(context.getPlayer().isShiftKeyDown())
if(player.isSneaking()) return InteractionResult.PASS;
return EnumActionResult.PASS;
if(world.isRemote) if(context.getLevel().isClientSide)
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
if(WebDisplays.INSTANCE.disableOwnershipThief) { if(WebDisplays.INSTANCE.disableOwnershipThief) {
Util.toast(player, "otDisabled"); Util.toast(context.getPlayer(), "otDisabled");
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
ItemStack stack = player.getHeldItem(hand); ItemStack stack = context.getPlayer().getItemInHand(context.getHand());
if(stack.hasTagCompound()) { if(stack.hasTag()) {
NBTTagCompound tag = stack.getTagCompound(); CompoundTag tag = stack.getTag();
if(tag.hasKey("PosX") && tag.hasKey("PosY") && tag.hasKey("PosZ") && tag.hasKey("Side")) { if(tag.contains("PosX") && tag.contains("PosY") && tag.contains("PosZ") && tag.contains("Side")) {
BlockPos bp = new BlockPos(tag.getInteger("PosX"), tag.getInteger("PosY"), tag.getInteger("PosZ")); BlockPos bp = new BlockPos(tag.getInt("PosX"), tag.getInt("PosY"), tag.getInt("PosZ"));
BlockSide side = BlockSide.values()[tag.getByte("Side")]; BlockSide side = BlockSide.values()[tag.getByte("Side")];
if(!(world.getBlockState(bp).getBlock() instanceof BlockScreen)) if(!(context.getLevel().getBlockState(bp).getBlock() instanceof BlockScreen))
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
TileEntity te = world.getTileEntity(bp); BlockEntity te = context.getLevel().getBlockEntity(bp);
if(te == null || !(te instanceof TileEntityScreen)) if(te == null || !(te instanceof TileEntityScreen))
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
TileEntityScreen tes = (TileEntityScreen) te; TileEntityScreen tes = (TileEntityScreen) te;
TileEntityScreen.Screen scr = tes.getScreen(side); TileEntityScreen.Screen scr = tes.getScreen(side);
if(scr == null) 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()); 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());
player.setHeldItem(hand, ItemStack.EMPTY); context.getPlayer().setItemInHand(context.getHand(), ItemStack.EMPTY);
tes.setOwner(side, player); tes.setOwner(side, context.getPlayer());
Util.toast(player, TextFormatting.AQUA, "newOwner"); Util.toast(context.getPlayer(), ChatFormatting.AQUA, "newOwner");
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
} }
if(!(world.getBlockState(pos_).getBlock() instanceof BlockScreen)) if(!(context.getLevel().getBlockState(context.getClickedPos()).getBlock() instanceof BlockScreen))
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
Vector3i pos = new Vector3i(pos_); Vector3i pos = new Vector3i(context.getClickedPos());
BlockSide side = BlockSide.values()[side_.ordinal()]; BlockSide side = BlockSide.values()[context.getHorizontalDirection().ordinal()];
Multiblock.findOrigin(world, pos, side, null); 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)) { if(te == null || !(te instanceof TileEntityScreen)) {
Util.toast(player, "turnOn"); Util.toast(context.getPlayer(), "turnOn");
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
if(((TileEntityScreen) te).getScreen(side) == null) if(((TileEntityScreen) te).getScreen(side) == null)
Util.toast(player, "turnOn"); Util.toast(context.getPlayer(), "turnOn");
else { else {
NBTTagCompound tag = new NBTTagCompound(); CompoundTag tag = new CompoundTag();
tag.setInteger("PosX", pos.x); tag.putInt("PosX", pos.x);
tag.setInteger("PosY", pos.y); tag.putInt("PosY", pos.y);
tag.setInteger("PosZ", pos.z); tag.putInt("PosZ", pos.z);
tag.setByte("Side", (byte) side.ordinal()); tag.putByte("Side", (byte) side.ordinal());
stack.setTagCompound(tag); stack.setTag(tag);
Util.toast(player, TextFormatting.AQUA, "screenSet"); 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!", player.getName(), player.getGameProfile().getId().toString(), pos.x, pos.y, pos.z, side.toString()); 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; return InteractionResult.SUCCESS;
}
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, @Nullable World world, List<String> 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);
} }
@Nullable @Nullable

View File

@ -4,34 +4,22 @@
package net.montoyo.wd.item; package net.montoyo.wd.item;
import com.mojang.realmsclient.gui.ChatFormatting; import net.minecraft.world.item.Item;
import net.minecraft.block.Block; import net.minecraft.world.item.ItemStack;
import net.minecraft.client.resources.I18n; import net.montoyo.wd.core.WDCreativeTab;
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 javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; 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) { public ItemPeripheral() {
super(block, block, (is) -> DefaultPeripheral.fromMetadata(is.getMetadata()).getName()); super(new Properties().tab(WDCreativeTab.TAB_REDSTONE));
} }
@Override //TODO what was this!
public boolean canPlaceBlockOnSide(World world, @Nonnull BlockPos pos_, @Nonnull EnumFacing side, EntityPlayer player, ItemStack stack) { /*@Override
public boolean canPlaceBlock(Level world, @Nonnull BlockPos pos_, @Nonnull EnumFacing side, EntityPlayer player, ItemStack stack) {
if(stack.getMetadata() != 0) //Keyboard if(stack.getMetadata() != 0) //Keyboard
return true; return true;
@ -49,28 +37,12 @@ public class ItemPeripheral extends ItemMultiTexture implements WDItem {
return true; return true;
else else
return world.isAirBlock(left) && !world.isAirBlock(left.down()) && BlockKeyboardRight.checkNeighborhood(world, left, null); 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<String> 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 @Nullable
@Override @Override
public String getWikiName(@Nonnull ItemStack is) { public String getWikiName(@Nonnull ItemStack is) {
return DefaultPeripheral.fromMetadata(is.getMetadata()).getWikiName(); return is.getItem().getName(is).getString();
} }
} }

View File

@ -4,7 +4,12 @@
package net.montoyo.wd.item; 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.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.WebDisplays;
import net.montoyo.wd.block.BlockScreen; import net.montoyo.wd.block.BlockScreen;
import net.montoyo.wd.data.ScreenConfigData; 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.Multiblock;
import net.montoyo.wd.utilities.Util; import net.montoyo.wd.utilities.Util;
import net.montoyo.wd.utilities.Vector3i; import net.montoyo.wd.utilities.Vector3i;
import org.lwjgl.system.CallbackI;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public class ItemScreenConfigurator extends Item implements WDItem { public class ItemScreenConfigurator extends Item implements WDItem {
public ItemScreenConfigurator() { public ItemScreenConfigurator(Properties properties) {
setUnlocalizedName("webdisplays.screencfg"); super(properties
setRegistryName("screencfg"); //setRegistryName("screencfg");
setMaxStackSize(1); .stacksTo(1)
setCreativeTab(WebDisplays.CREATIVE_TAB); .tab(WebDisplays.CREATIVE_TAB));
} }
@Override @Override
@Nonnull public InteractionResult useOn(UseOnContext context) {
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side_, float hitX, float hitY, float hitZ) { if(context.getPlayer().isShiftKeyDown() || !(context.getLevel().getBlockState(context.getClickedPos()).getBlock() instanceof BlockScreen))
if(player.isSneaking() || !(world.getBlockState(pos).getBlock() instanceof BlockScreen)) return InteractionResult.PASS;
return EnumActionResult.PASS;
if(world.isRemote) if(context.getLevel().isClientSide)
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
Vector3i origin = new Vector3i(pos); Vector3i origin = new Vector3i(context.getClickedPos());
BlockSide side = BlockSide.values()[side_.ordinal()]; BlockSide side = BlockSide.values()[context.getHorizontalDirection().ordinal()];
Multiblock.findOrigin(world, origin, side, null); Multiblock.findOrigin(context.getLevel(), origin, side, null);
TileEntity te = world.getTileEntity(origin.toBlock()); BlockEntity te = context.getLevel().getBlockEntity(origin.toBlock());
if(te == null || !(te instanceof TileEntityScreen)) { if(te == null || !(te instanceof TileEntityScreen)) {
Util.toast(player, "turnOn"); Util.toast(context.getPlayer(), "turnOn");
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
TileEntityScreen.Screen scr = ((TileEntityScreen) te).getScreen(side); TileEntityScreen.Screen scr = ((TileEntityScreen) te).getScreen(side);
if(scr == null) if(scr == null)
Util.toast(player, "turnOn"); Util.toast(context.getPlayer(), "turnOn");
else else
(new ScreenConfigData(origin, side, scr)).sendTo((EntityPlayerMP) player); (new ScreenConfigData(origin, side, scr)).sendTo((ServerPlayer) context.getPlayer());
return EnumActionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
} }

View File

@ -10,6 +10,7 @@ import net.montoyo.wd.core.DefaultUpgrade;
import net.montoyo.wd.core.IUpgrade; import net.montoyo.wd.core.IUpgrade;
import net.montoyo.wd.entity.TileEntityScreen; import net.montoyo.wd.entity.TileEntityScreen;
import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.BlockSide;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -49,4 +50,9 @@ public class ItemUpgrade extends ItemMulti implements IUpgrade, WDItem {
else else
return "webdisplays:" + is; return "webdisplays:" + is;
} }
@Override
public String getWikiName(@NotNull ItemStack is) {
return is.getItem().getName(is).getString();
}
} }

View File

@ -20,6 +20,5 @@ public interface WDItem {
tt.add("" + ChatFormatting.GRAY + I18n.get("item.webdisplays.wiki")); tt.add("" + ChatFormatting.GRAY + I18n.get("item.webdisplays.wiki"));
} }
public String getWikiName(@Nonnull ItemStack is); String getWikiName(@Nonnull ItemStack is);
} }