+ Server Block [WIP]

This commit is contained in:
Nicolas BARBOTIN 2018-02-08 01:35:03 +01:00
parent edab9d80bd
commit ec09b2a7f5
11 changed files with 129 additions and 37 deletions

View File

@ -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

View File

@ -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<? extends TileEntityPeripheralBase> cls = DefaultPeripheral.fromMetadata(meta).getTEClass();
public TileEntity createNewTileEntity(@Nonnull World world, int meta) {
Class<? extends TileEntity> 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;
}

View File

@ -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");

View File

@ -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<? extends TileEntityPeripheralBase> teClass;
private final Class<? extends TileEntity> teClass;
DefaultPeripheral(String name, Class<? extends TileEntityPeripheralBase> te) {
DefaultPeripheral(String name, Class<? extends TileEntity> te) {
this.name = name;
teClass = te;
}
@ -41,7 +40,7 @@ public enum DefaultPeripheral implements IStringSerializable {
return name;
}
public Class<? extends TileEntityPeripheralBase> getTEClass() {
public Class<? extends TileEntity> getTEClass() {
return teClass;
}

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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" }
}
}

View File

@ -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

View File

@ -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"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B