From ce2c1d881f2bd552c92e1b2531f870109c879905 Mon Sep 17 00:00:00 2001 From: Nicolas BARBOTIN Date: Sat, 3 Feb 2018 20:11:16 +0100 Subject: [PATCH] + Finished the rotation thing * Tweaked the linker a bit --- README.md | 1 - .../net/montoyo/wd/block/BlockScreen.java | 29 +++++++++++++++++-- .../java/net/montoyo/wd/item/ItemLinker.java | 29 ++++++++++++------- .../assets/webdisplays/lang/en_us.lang | 7 +++++ 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e51fda2..af494e3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The tex * Read config (see "Config elements" below) ### TODO -* Top/bottom screen orientation * GuiSetURL2 missing buttons * Automatically add protocol to URLs * Using the remote control tool too far away (with a chunk loader ofc) may trigger distance guard in SMessageScreenCtrl diff --git a/src/main/java/net/montoyo/wd/block/BlockScreen.java b/src/main/java/net/montoyo/wd/block/BlockScreen.java index f0bda7a..58cac43 100644 --- a/src/main/java/net/montoyo/wd/block/BlockScreen.java +++ b/src/main/java/net/montoyo/wd/block/BlockScreen.java @@ -240,10 +240,35 @@ public class BlockScreen extends WDBlockContainer { if(side != BlockSide.BOTTOM) cy = 1.f - cy; + switch(scr.rotation) { + case ROT_90: + cy = 1.0f - cy; + break; + + case ROT_180: + cx = 1.0f - cx; + cy = 1.0f - cy; + break; + + case ROT_270: + cx = 1.0f - cx; + break; + + default: + break; + } + cx *= (float) scr.resolution.x; cy *= (float) scr.resolution.y; - dst.x = (int) cx; - dst.y = (int) cy; + + if(scr.rotation.isVertical) { + dst.x = (int) cy; + dst.y = (int) cx; + } else { + dst.x = (int) cx; + dst.y = (int) cy; + } + return true; } diff --git a/src/main/java/net/montoyo/wd/item/ItemLinker.java b/src/main/java/net/montoyo/wd/item/ItemLinker.java index a5c3507..8363cbd 100644 --- a/src/main/java/net/montoyo/wd/item/ItemLinker.java +++ b/src/main/java/net/montoyo/wd/item/ItemLinker.java @@ -4,6 +4,7 @@ package net.montoyo.wd.item; +import com.mojang.realmsclient.gui.ChatFormatting; import net.minecraft.block.state.IBlockState; import net.minecraft.client.resources.I18n; import net.minecraft.client.util.ITooltipFlag; @@ -31,6 +32,7 @@ import net.montoyo.wd.utilities.Multiblock; import net.montoyo.wd.utilities.Util; import net.montoyo.wd.utilities.Vector3i; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; @@ -44,17 +46,15 @@ public class ItemLinker extends Item { } @Override + @Nonnull public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos_, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { - if(player.isSneaking()) - return EnumActionResult.PASS; - if(world.isRemote) return EnumActionResult.SUCCESS; ItemStack stack = player.getHeldItem(hand); - if(stack.hasTagCompound()) { - NBTTagCompound tag = stack.getTagCompound(); + NBTTagCompound tag = stack.getTagCompound(); + if(tag != null) { if(tag.hasKey("ScreenX") && tag.hasKey("ScreenY") && tag.hasKey("ScreenZ") && tag.hasKey("ScreenSide")) { IBlockState state = world.getBlockState(pos_); IPeripheral target; @@ -64,7 +64,12 @@ public class ItemLinker extends Item { else { TileEntity te = world.getTileEntity(pos_); if(te == null || !(te instanceof IPeripheral)) { - Util.toast(player, "peripheral"); + if(player.isSneaking()) { + Util.toast(player, TextFormatting.GOLD, "linkAbort"); + stack.setTagCompound(null); + } else + Util.toast(player, "peripheral"); + return EnumActionResult.SUCCESS; } @@ -108,7 +113,7 @@ public class ItemLinker extends Item { else if((scr.rightsFor(player) & ScreenRights.MANAGE_UPGRADES) == 0) Util.toast(player, "restrictions"); else { - NBTTagCompound tag = new NBTTagCompound(); + tag = new NBTTagCompound(); tag.setInteger("ScreenX", pos.x); tag.setInteger("ScreenY", pos.y); tag.setInteger("ScreenZ", pos.z); @@ -124,13 +129,17 @@ public class ItemLinker extends Item { @SideOnly(Side.CLIENT) @Override public void addInformation(ItemStack stack, @Nullable World world, List tt, ITooltipFlag ttFlag) { - if(stack.hasTagCompound()) { - NBTTagCompound tag = stack.getTagCompound(); + 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", BlockSide.values()[tag.getByte("ScreenSide")].toString())); + tt.add(I18n.format("webdisplays.linker.sideInfo", I18n.format("webdisplays.side." + side.toString().toLowerCase()))); return; } } diff --git a/src/main/resources/assets/webdisplays/lang/en_us.lang b/src/main/resources/assets/webdisplays/lang/en_us.lang index 329002f..d921ae2 100644 --- a/src/main/resources/assets/webdisplays/lang/en_us.lang +++ b/src/main/resources/assets/webdisplays/lang/en_us.lang @@ -48,6 +48,7 @@ webdisplays.message.missingCC=ComputerCraft is not available. webdisplays.message.missingOC=OpenComputers is not available. webdisplays.message.upgradeError=Upgrade error :( Check logs... webdisplays.message.upgradeOk=Upgrade installed! +webdisplays.message.linkAbort=Linker reset webdisplays.gui.screencfg.owner=Screen owner: webdisplays.gui.screencfg.friends=Friends: webdisplays.gui.screencfg.permissions=Permissions: @@ -102,3 +103,9 @@ advancements.webdisplays.upgrade.title=More than a screen advancements.webdisplays.upgrade.description=Install your first upgrade advancements.webdisplays.laser.title=Don't aim the eyes advancements.webdisplays.laser.description=Craft a laser pointer! +webdisplays.side.bottom=Bottom +webdisplays.side.top=Top +webdisplays.side.north=North +webdisplays.side.south=South +webdisplays.side.west=West +webdisplays.side.east=East