From ec09b2a7f54276b23e8f42fa2b78d895a4b5d6fc Mon Sep 17 00:00:00 2001 From: Nicolas BARBOTIN Date: Thu, 8 Feb 2018 01:35:03 +0100 Subject: [PATCH] + Server Block [WIP] --- README.md | 2 +- .../net/montoyo/wd/block/BlockPeripheral.java | 71 +++++++++++------- .../net/montoyo/wd/client/ClientProxy.java | 1 + .../montoyo/wd/core/DefaultPeripheral.java | 15 ++-- .../montoyo/wd/entity/TileEntityServer.java | 56 ++++++++++++++ .../wd/net/client/CMessageOpenGui.java | 1 + .../webdisplays/blockstates/peripheral.json | 7 +- .../assets/webdisplays/lang/en_us.lang | 1 + .../webdisplays/models/block/server.json | 12 +++ .../webdisplays/textures/blocks/server.png | Bin 0 -> 520 bytes .../webdisplays/textures/blocks/server2.png | Bin 0 -> 351 bytes 11 files changed, 129 insertions(+), 37 deletions(-) create mode 100644 src/main/java/net/montoyo/wd/entity/TileEntityServer.java create mode 100644 src/main/resources/assets/webdisplays/models/block/server.json create mode 100644 src/main/resources/assets/webdisplays/textures/blocks/server.png create mode 100644 src/main/resources/assets/webdisplays/textures/blocks/server2.png diff --git a/README.md b/README.md index 3a77256..4963482 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The tex ### Missing features * Peripheral: OpenComputers interface -* Server blocks (to store some of the player's web pages) * Read config (see "Config elements" below) * Miniserv timeout +* Recipe for server block ### TODO * French translations diff --git a/src/main/java/net/montoyo/wd/block/BlockPeripheral.java b/src/main/java/net/montoyo/wd/block/BlockPeripheral.java index 442d27f..e7abfae 100644 --- a/src/main/java/net/montoyo/wd/block/BlockPeripheral.java +++ b/src/main/java/net/montoyo/wd/block/BlockPeripheral.java @@ -34,12 +34,13 @@ import net.montoyo.wd.WebDisplays; import net.montoyo.wd.core.DefaultPeripheral; import net.montoyo.wd.entity.TileEntityKeyboard; import net.montoyo.wd.entity.TileEntityPeripheralBase; +import net.montoyo.wd.entity.TileEntityServer; import net.montoyo.wd.item.ItemLinker; import net.montoyo.wd.item.ItemPeripheral; import net.montoyo.wd.utilities.BlockSide; import net.montoyo.wd.utilities.Log; -import javax.annotation.Nullable; +import javax.annotation.Nonnull; public class BlockPeripheral extends WDBlockContainer { @@ -61,12 +62,15 @@ public class BlockPeripheral extends WDBlockContainer { } @Override + @Nonnull protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, properties); } @Override - public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing rrezozei, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { + @Nonnull + public IBlockState getStateForPlacement(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing nocare, float hitX, + float hitY, float hitZ, int meta, @Nonnull EntityLivingBase placer, EnumHand hand) { int rot = MathHelper.floor(((double) (placer.rotationYaw * 4.0f / 360.0f)) + 2.5) & 3; return getDefaultState().withProperty(type, DefaultPeripheral.fromMetadata(meta)).withProperty(facing, rot); } @@ -78,6 +82,7 @@ public class BlockPeripheral extends WDBlockContainer { } @Override + @Nonnull public IBlockState getStateFromMeta(int meta) { DefaultPeripheral dp = DefaultPeripheral.fromMetadata(meta); IBlockState state = getDefaultState().withProperty(type, dp); @@ -93,10 +98,9 @@ public class BlockPeripheral extends WDBlockContainer { return state.getValue(type).toMetadata(state.getValue(facing)); } - @Nullable @Override - public TileEntity createNewTileEntity(World world, int meta) { - Class cls = DefaultPeripheral.fromMetadata(meta).getTEClass(); + public TileEntity createNewTileEntity(@Nonnull World world, int meta) { + Class cls = DefaultPeripheral.fromMetadata(meta).getTEClass(); if(cls == null) return null; @@ -110,6 +114,7 @@ public class BlockPeripheral extends WDBlockContainer { } @Override + @Nonnull public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } @@ -128,10 +133,13 @@ public class BlockPeripheral extends WDBlockContainer { return false; TileEntity te = world.getTileEntity(pos); - if(te == null || !(te instanceof TileEntityPeripheralBase)) - return false; - return ((TileEntityPeripheralBase) te).onRightClick(player, hand, BlockSide.values()[facing.ordinal()]); + if(te instanceof TileEntityPeripheralBase) + return ((TileEntityPeripheralBase) te).onRightClick(player, hand, BlockSide.values()[facing.ordinal()]); + else if(te instanceof TileEntityServer) + return ((TileEntityServer) te).onPlayerRightClick(player); + else + return false; } @Override @@ -160,39 +168,48 @@ public class BlockPeripheral extends WDBlockContainer { } @Override + @Nonnull public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return state.getValue(type) == DefaultPeripheral.KEYBOARD ? BlockKeyboardRight.KEYBOARD_AABB : FULL_BLOCK_AABB; } @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { - if(world.isRemote || state.getValue(type) != DefaultPeripheral.KEYBOARD) + if(world.isRemote) return; - //Keyboard special treatment - int f = state.getValue(facing); - Vec3i dir = EnumFacing.getHorizontal(f).rotateY().getDirectionVec(); - BlockPos left = pos.add(dir); - BlockPos right = pos.subtract(dir); + if(state.getValue(type) == DefaultPeripheral.KEYBOARD) { + //Keyboard special treatment + int f = state.getValue(facing); + Vec3i dir = EnumFacing.getHorizontal(f).rotateY().getDirectionVec(); + BlockPos left = pos.add(dir); + BlockPos right = pos.subtract(dir); - if(!world.isAirBlock(pos.down()) && BlockKeyboardRight.checkNeighborhood(world, pos, null)) { - if(world.isAirBlock(right) && !world.isAirBlock(right.down()) && BlockKeyboardRight.checkNeighborhood(world, right, pos)) { - world.setBlockState(right, WebDisplays.INSTANCE.blockKbRight.getDefaultState().withProperty(BlockKeyboardRight.facing, f)); - return; - } else if(world.isAirBlock(left) && !world.isAirBlock(left.down()) && BlockKeyboardRight.checkNeighborhood(world, left, pos)) { - world.setBlockState(left, state); - world.setBlockState(pos, WebDisplays.INSTANCE.blockKbRight.getDefaultState().withProperty(BlockKeyboardRight.facing, f)); - return; + if(!world.isAirBlock(pos.down()) && BlockKeyboardRight.checkNeighborhood(world, pos, null)) { + if(world.isAirBlock(right) && !world.isAirBlock(right.down()) && BlockKeyboardRight.checkNeighborhood(world, right, pos)) { + world.setBlockState(right, WebDisplays.INSTANCE.blockKbRight.getDefaultState().withProperty(BlockKeyboardRight.facing, f)); + return; + } else if(world.isAirBlock(left) && !world.isAirBlock(left.down()) && BlockKeyboardRight.checkNeighborhood(world, left, pos)) { + world.setBlockState(left, state); + world.setBlockState(pos, WebDisplays.INSTANCE.blockKbRight.getDefaultState().withProperty(BlockKeyboardRight.facing, f)); + return; + } } - } - //Not good; remove this shit... - world.setBlockToAir(pos); - if(!(placer instanceof EntityPlayer) || !((EntityPlayer) placer).isCreative()) - dropBlockAsItem(world, pos, state, 0); + //Not good; remove this shit... + world.setBlockToAir(pos); + if(!(placer instanceof EntityPlayer) || !((EntityPlayer) placer).isCreative()) + dropBlockAsItem(world, pos, state, 0); + } else if(placer instanceof EntityPlayer) { + TileEntity te = world.getTileEntity(pos); + + if(te instanceof TileEntityServer) + ((TileEntityServer) te).setOwner((EntityPlayer) placer); + } } @Override + @Nonnull public EnumPushReaction getMobilityFlag(IBlockState state) { return EnumPushReaction.IGNORE; } diff --git a/src/main/java/net/montoyo/wd/client/ClientProxy.java b/src/main/java/net/montoyo/wd/client/ClientProxy.java index 43b057e..886834c 100644 --- a/src/main/java/net/montoyo/wd/client/ClientProxy.java +++ b/src/main/java/net/montoyo/wd/client/ClientProxy.java @@ -440,6 +440,7 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi registerItemModel(wd.blockPeripheral.getItem(), 2, "facing=2,type=cointerface"); registerItemModel(wd.blockPeripheral.getItem(), 3, "facing=0,type=remotectrl"); registerItemModel(wd.blockPeripheral.getItem(), 7, "facing=0,type=redstonectrl"); + registerItemModel(wd.blockPeripheral.getItem(), 11, "facing=0,type=server"); registerItemModel(wd.itemScreenCfg, 0, "normal"); registerItemModel(wd.itemOwnerThief, 0, "normal"); registerItemModel(wd.itemLinker, 0, "normal"); diff --git a/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java b/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java index 80c1deb..7d078ad 100644 --- a/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java +++ b/src/main/java/net/montoyo/wd/core/DefaultPeripheral.java @@ -4,11 +4,9 @@ package net.montoyo.wd.core; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IStringSerializable; -import net.montoyo.wd.entity.TileEntityKeyboard; -import net.montoyo.wd.entity.TileEntityPeripheralBase; -import net.montoyo.wd.entity.TileEntityRCtrl; -import net.montoyo.wd.entity.TileEntityRedCtrl; +import net.montoyo.wd.entity.*; import javax.annotation.Nonnull; @@ -18,12 +16,13 @@ public enum DefaultPeripheral implements IStringSerializable { CC_INTERFACE("ccinterface", null), OC_INTERFACE("cointerface", null), REMOTE_CONTROLLER("remotectrl", TileEntityRCtrl.class), //WITHOUT FACING (>= 3) - REDSTONE_CONTROLLER("redstonectrl", TileEntityRedCtrl.class); + REDSTONE_CONTROLLER("redstonectrl", TileEntityRedCtrl.class), + SERVER("server", TileEntityServer.class); private final String name; - private final Class teClass; + private final Class teClass; - DefaultPeripheral(String name, Class te) { + DefaultPeripheral(String name, Class te) { this.name = name; teClass = te; } @@ -41,7 +40,7 @@ public enum DefaultPeripheral implements IStringSerializable { return name; } - public Class getTEClass() { + public Class getTEClass() { return teClass; } diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityServer.java b/src/main/java/net/montoyo/wd/entity/TileEntityServer.java new file mode 100644 index 0000000..67a38da --- /dev/null +++ b/src/main/java/net/montoyo/wd/entity/TileEntityServer.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2018 BARBOTIN Nicolas + */ + +package net.montoyo.wd.entity; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.montoyo.wd.utilities.NameUUIDPair; + +import javax.annotation.Nonnull; +import java.util.UUID; + +public class TileEntityServer extends TileEntity { + + private NameUUIDPair owner; + + @Override + public void readFromNBT(NBTTagCompound tag) { + super.readFromNBT(tag); + + long msb = tag.getLong("OwnerMSB"); + long lsb = tag.getLong("OwnerLSB"); + String str = tag.getString("OwnerName"); + owner = new NameUUIDPair(str, new UUID(msb, lsb)); + } + + @Override + @Nonnull + public NBTTagCompound writeToNBT(NBTTagCompound tag) { + super.writeToNBT(tag); + + if(owner != null) { + tag.setLong("OwnerMSB", owner.uuid.getMostSignificantBits()); + tag.setLong("OwnerLSB", owner.uuid.getLeastSignificantBits()); + tag.setString("OwnerName", owner.name); + } + + return tag; + } + + public void setOwner(EntityPlayer ep) { + owner = new NameUUIDPair(ep.getGameProfile()); + markDirty(); + } + + public boolean onPlayerRightClick(EntityPlayer ply) { + if(world.isRemote) + return true; + + + return true; + } + +} diff --git a/src/main/java/net/montoyo/wd/net/client/CMessageOpenGui.java b/src/main/java/net/montoyo/wd/net/client/CMessageOpenGui.java index 1f64e89..a254d7b 100644 --- a/src/main/java/net/montoyo/wd/net/client/CMessageOpenGui.java +++ b/src/main/java/net/montoyo/wd/net/client/CMessageOpenGui.java @@ -11,6 +11,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.montoyo.mcef.utilities.Log; import net.montoyo.wd.WebDisplays; import net.montoyo.wd.data.GuiData; +import net.montoyo.wd.net.Message; import net.montoyo.wd.utilities.Util; @Message(messageId = 3, side = Side.CLIENT) diff --git a/src/main/resources/assets/webdisplays/blockstates/peripheral.json b/src/main/resources/assets/webdisplays/blockstates/peripheral.json index 2dfa416..0118006 100644 --- a/src/main/resources/assets/webdisplays/blockstates/peripheral.json +++ b/src/main/resources/assets/webdisplays/blockstates/peripheral.json @@ -23,6 +23,11 @@ "facing=0,type=redstonectrl": { "model": "webdisplays:redctrl" }, "facing=1,type=redstonectrl": { "model": "webdisplays:redctrl" }, "facing=2,type=redstonectrl": { "model": "webdisplays:redctrl" }, - "facing=3,type=redstonectrl": { "model": "webdisplays:redctrl" } + "facing=3,type=redstonectrl": { "model": "webdisplays:redctrl" }, + + "facing=0,type=server": { "model": "webdisplays:server" }, + "facing=1,type=server": { "model": "webdisplays:server" }, + "facing=2,type=server": { "model": "webdisplays:server" }, + "facing=3,type=server": { "model": "webdisplays:server" } } } diff --git a/src/main/resources/assets/webdisplays/lang/en_us.lang b/src/main/resources/assets/webdisplays/lang/en_us.lang index d921ae2..e770751 100644 --- a/src/main/resources/assets/webdisplays/lang/en_us.lang +++ b/src/main/resources/assets/webdisplays/lang/en_us.lang @@ -6,6 +6,7 @@ tile.webdisplays.peripheral.remotectrl.name=Remote Controller tile.webdisplays.peripheral.ccinterface.name=ComputerCraft Interface tile.webdisplays.peripheral.cointerface.name=OpenComputers Interface tile.webdisplays.peripheral.redstonectrl.name=Redstone Controller +tile.webdisplays.peripheral.server.name=Server item.webdisplays.screencfg.name=Screen Configurator item.webdisplays.ownerthief.name=Ownership Thief [ADMIN] item.webdisplays.linker.name=Linking Tool diff --git a/src/main/resources/assets/webdisplays/models/block/server.json b/src/main/resources/assets/webdisplays/models/block/server.json new file mode 100644 index 0000000..b08e2f4 --- /dev/null +++ b/src/main/resources/assets/webdisplays/models/block/server.json @@ -0,0 +1,12 @@ +{ + "parent": "block/cube", + "textures": { + "particle": "webdisplays:blocks/server", + "down": "webdisplays:blocks/server2", + "up": "webdisplays:blocks/server2", + "north": "webdisplays:blocks/server", + "east": "webdisplays:blocks/server", + "south": "webdisplays:blocks/server", + "west": "webdisplays:blocks/server" + } +} diff --git a/src/main/resources/assets/webdisplays/textures/blocks/server.png b/src/main/resources/assets/webdisplays/textures/blocks/server.png new file mode 100644 index 0000000000000000000000000000000000000000..11199c4b28590ebefb36b2d8a09e2998376d949c GIT binary patch literal 520 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkEYGO%h zib8p2Nrr;Er*A-tUMf2S17nV-i(`nz>7|oTdnr4LwC!JIrx@4a_CoO{58I|Mn@S(9 z`YiUD!EUNRy7Bo3>#EGVZ}KZ~Dd~yu&bnZ<>`lm3oh7&P^aZ{;6n0sCo&S0M>{s7^ zAGB=mc(C_)HGji3srR;lB8(5_EY|YUbmHhJ?o;vn(X%A8>sl0Zfq_lUCHpo8p7;E5 zj9vDvzAgcK!0LR{Z`v?G2@Elk;v({pJw-c+TXC~ zZqDc2mBGaV>9JiCPkoljG@G58dUjvp)c0F8l;yH4cYBFX3F_GT?d-QR+P|JA)VQ<@ z%#&S`=`~5E`1K^mjk)rS;yew@V^^%()De)IE2z*CFmKf#c4phN4zH6Rq=6#D)78&q Iol`;+0JPT8ga7~l literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/webdisplays/textures/blocks/server2.png b/src/main/resources/assets/webdisplays/textures/blocks/server2.png new file mode 100644 index 0000000000000000000000000000000000000000..12cdfecc899f8a5c99c1fe17e84780d4750b4af6 GIT binary patch literal 351 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)0nvsJBrx8Yse9;1OBO zz`!jG!i)^F=12eq*-JcqUD+QoaWIH7X3X2G0u++X42dXl&d<$F%_{+N85o?4QWHy3 zQxwWGOEMJPJ$(aG^itV@;)gw5978Nl&kc6uYBAuMbFAaOK#j}!eRqoIshFLdH|5Q( zU6&f2G-syF$h@>kXWgoVv>B3Tco-a942*dWGcW{%x-6OU;9WxK(Ov6a9Nd)J=5lONI|G7Ic_&hBpU! zm2*9|XqwNJmF6aMoN?B&m+K#|O$qW^PP{=Ufc)v{>gTe~DWM4fcol*J literal 0 HcmV?d00001