From f3ad36e6a66f803e3605ef26d799e085f4a389c9 Mon Sep 17 00:00:00 2001 From: Christian Knaapen Date: Thu, 10 Jan 2019 17:21:56 +0100 Subject: [PATCH] Fixed rotation and various small bugs. --- build.gradle | 2 +- .../effortlessbuilding/BuildModifiers.java | 2 +- .../EffortlessBuilding.java | 2 +- .../effortlessbuilding/EventHandler.java | 3 +- .../effortlessbuilding/RadialMirror.java | 89 ++++++++++++------- .../BuildModifierCapabilityManager.java | 2 + .../helper/RenderHelper.java | 1 + .../effortlessbuilding/proxy/ClientProxy.java | 3 +- 8 files changed, 65 insertions(+), 39 deletions(-) diff --git a/build.gradle b/build.gradle index ff7fcc2..9696a6e 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge' //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. -version = "0.6" +version = "1.0" group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "effortlessbuilding" diff --git a/src/main/java/nl/requios/effortlessbuilding/BuildModifiers.java b/src/main/java/nl/requios/effortlessbuilding/BuildModifiers.java index 45f6d15..41d4df8 100644 --- a/src/main/java/nl/requios/effortlessbuilding/BuildModifiers.java +++ b/src/main/java/nl/requios/effortlessbuilding/BuildModifiers.java @@ -85,7 +85,7 @@ public class BuildModifiers { BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(event.getPlayer()); //Only use own place event if anything is enabled if (isEnabled(buildSettings, event.getPos())) { - EffortlessBuilding.packetHandler.sendTo(new BlockPlacedMessage(), (EntityPlayerMP) event.getPlayer()); + //EffortlessBuilding.packetHandler.sendTo(new BlockPlacedMessage(), (EntityPlayerMP) event.getPlayer()); event.setCanceled(true); } diff --git a/src/main/java/nl/requios/effortlessbuilding/EffortlessBuilding.java b/src/main/java/nl/requios/effortlessbuilding/EffortlessBuilding.java index 99c0bdf..462ada1 100644 --- a/src/main/java/nl/requios/effortlessbuilding/EffortlessBuilding.java +++ b/src/main/java/nl/requios/effortlessbuilding/EffortlessBuilding.java @@ -36,7 +36,7 @@ public class EffortlessBuilding { public static final String MODID = "effortlessbuilding"; public static final String NAME = "Effortless Building"; - public static final String VERSION = "0.6"; + public static final String VERSION = "1.0"; @Mod.Instance(EffortlessBuilding.MODID) public static EffortlessBuilding instance; diff --git a/src/main/java/nl/requios/effortlessbuilding/EventHandler.java b/src/main/java/nl/requios/effortlessbuilding/EventHandler.java index e182218..951182f 100644 --- a/src/main/java/nl/requios/effortlessbuilding/EventHandler.java +++ b/src/main/java/nl/requios/effortlessbuilding/EventHandler.java @@ -67,7 +67,8 @@ public class EventHandler @SubscribeEvent public static void onBlockPlaced(BlockEvent.PlaceEvent event) { - //BuildModifiers.onBlockPlaced(event); + //Still call it to cancel event + BuildModifiers.onBlockPlaced(event); } @SubscribeEvent diff --git a/src/main/java/nl/requios/effortlessbuilding/RadialMirror.java b/src/main/java/nl/requios/effortlessbuilding/RadialMirror.java index d85c70f..1fcf834 100644 --- a/src/main/java/nl/requios/effortlessbuilding/RadialMirror.java +++ b/src/main/java/nl/requios/effortlessbuilding/RadialMirror.java @@ -70,8 +70,8 @@ public class RadialMirror { } Vec3d relNewVec = relStartVec.rotateYaw((float) curAngle); - Vec3d newVec = r.position.add(relNewVec); - coordinates.add(new BlockPos(newVec)); + BlockPos newBlockPos = new BlockPos(r.position.add(relNewVec)); + if (!coordinates.contains(newBlockPos) && !newBlockPos.equals(startPos)) coordinates.add(newBlockPos); } return coordinates; @@ -79,6 +79,7 @@ public class RadialMirror { public static List findBlockStates(EntityPlayer player, BlockPos startPos, IBlockState blockState, ItemStack itemStack, List itemStacks) { List blockStates = new ArrayList<>(); + List coordinates = new ArrayList<>(); //to keep track of duplicates //find radial mirror settings for the player that placed the block RadialMirrorSettings r = BuildSettingsManager.getBuildSettings(player).getRadialMirrorSettings(); @@ -92,17 +93,11 @@ public class RadialMirror { Vec3d relStartVec = startVec.subtract(r.position); double startAngleToCenter = MathHelper.atan2(relStartVec.x, relStartVec.z); - if (startAngleToCenter < 0) startAngleToCenter += Math.PI; - double startAngleInSlice = startAngleToCenter % sliceAngle; + double startAngleToCenterMod = startAngleToCenter < 0 ? startAngleToCenter + Math.PI : startAngleToCenter; + double startAngleInSlice = startAngleToCenterMod % sliceAngle; //Rotate the original blockstate - if (startAngleToCenter < -0.75 * Math.PI || startAngleToCenter > 0.75 * Math.PI) { - blockState = blockState.withRotation(Rotation.CLOCKWISE_180); - } else if (startAngleToCenter < -0.25 * Math.PI) { - blockState = blockState.withRotation(Rotation.CLOCKWISE_90); - } else if (startAngleToCenter > 0.25 * Math.PI) { - blockState = blockState.withRotation(Rotation.COUNTERCLOCKWISE_90); - } + blockState = rotateOriginalBlockState(startAngleToCenter, blockState); //Randomizer bag synergy IItemHandler bagInventory = null; @@ -121,37 +116,20 @@ public class RadialMirror { } Vec3d relNewVec = relStartVec.rotateYaw((float) curAngle); - Vec3d newVec = r.position.add(relNewVec); + BlockPos newBlockPos = new BlockPos(r.position.add(relNewVec)); + if (coordinates.contains(newBlockPos) || newBlockPos.equals(startPos)) continue; //filter out duplicates + coordinates.add(newBlockPos); //Randomizer bag synergy if (bagInventory != null) { itemStack = ItemRandomizerBag.pickRandomStack(bagInventory); newBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, startPos, EnumFacing.UP, new Vec3d(0, 0, 0), EnumHand.MAIN_HAND); + + newBlockState = rotateOriginalBlockState(startAngleToCenter, newBlockState); } //rotate - double angleToCenter = MathHelper.atan2(relNewVec.x, relNewVec.z); //between -PI and PI - - if (angleToCenter < -0.75 * Math.PI || angleToCenter > 0.75 * Math.PI) { - newBlockState = newBlockState.withRotation(Rotation.CLOCKWISE_180); - if (r.alternate && i%2 == 1) { - newBlockState = newBlockState.withMirror(Mirror.FRONT_BACK); - } - } else if (angleToCenter < -0.25 * Math.PI) { - newBlockState = newBlockState.withRotation(Rotation.CLOCKWISE_90); - if (r.alternate && i%2 == 1) { - newBlockState = newBlockState.withMirror(Mirror.LEFT_RIGHT); - } - } else if (angleToCenter > 0.25 * Math.PI) { - newBlockState = newBlockState.withRotation(Rotation.COUNTERCLOCKWISE_90); - if (r.alternate && i%2 == 1) { - newBlockState = newBlockState.withMirror(Mirror.LEFT_RIGHT); - } - } else { - if (r.alternate && i%2 == 1) { - newBlockState = newBlockState.withMirror(Mirror.FRONT_BACK); - } - } + newBlockState = rotateBlockState(relNewVec, newBlockState, r.alternate && i%2 == 1); blockStates.add(newBlockState); itemStacks.add(itemStack); @@ -160,6 +138,49 @@ public class RadialMirror { return blockStates; } + private static IBlockState rotateOriginalBlockState(double startAngleToCenter, IBlockState blockState) { + IBlockState newBlockState = blockState; + + if (startAngleToCenter < -0.751 * Math.PI || startAngleToCenter > 0.749 * Math.PI) { + newBlockState = blockState.withRotation(Rotation.CLOCKWISE_180); + } else if (startAngleToCenter < -0.251 * Math.PI) { + newBlockState = blockState.withRotation(Rotation.COUNTERCLOCKWISE_90); + } else if (startAngleToCenter > 0.249 * Math.PI) { + newBlockState = blockState.withRotation(Rotation.CLOCKWISE_90); + } + + return newBlockState; + } + + private static IBlockState rotateBlockState(Vec3d relVec, IBlockState blockState, boolean alternate) { + IBlockState newBlockState; + double angleToCenter = MathHelper.atan2(relVec.x, relVec.z); //between -PI and PI + + if (angleToCenter < -0.751 * Math.PI || angleToCenter > 0.749 * Math.PI) { + newBlockState = blockState.withRotation(Rotation.CLOCKWISE_180); + if (alternate) { + newBlockState = newBlockState.withMirror(Mirror.FRONT_BACK); + } + } else if (angleToCenter < -0.251 * Math.PI) { + newBlockState = blockState.withRotation(Rotation.CLOCKWISE_90); + if (alternate) { + newBlockState = newBlockState.withMirror(Mirror.LEFT_RIGHT); + } + } else if (angleToCenter > 0.249 * Math.PI) { + newBlockState = blockState.withRotation(Rotation.COUNTERCLOCKWISE_90); + if (alternate) { + newBlockState = newBlockState.withMirror(Mirror.LEFT_RIGHT); + } + } else { + newBlockState = blockState; + if (alternate) { + newBlockState = newBlockState.withMirror(Mirror.FRONT_BACK); + } + } + + return newBlockState; + } + public static boolean isEnabled(RadialMirrorSettings r, BlockPos startPos) { if (r == null || !r.enabled) return false; diff --git a/src/main/java/nl/requios/effortlessbuilding/capability/BuildModifierCapabilityManager.java b/src/main/java/nl/requios/effortlessbuilding/capability/BuildModifierCapabilityManager.java index 4be938f..ef59466 100644 --- a/src/main/java/nl/requios/effortlessbuilding/capability/BuildModifierCapabilityManager.java +++ b/src/main/java/nl/requios/effortlessbuilding/capability/BuildModifierCapabilityManager.java @@ -89,6 +89,8 @@ public class BuildModifierCapabilityManager { compound.setInteger("radialMirrorSlices", r.slices); compound.setBoolean("radialMirrorAlternate", r.alternate); compound.setInteger("radialMirrorRadius", r.radius); + compound.setBoolean("radialMirrorDrawLines", r.drawLines); + compound.setBoolean("radialMirrorDrawPlanes", r.drawPlanes); return compound; } diff --git a/src/main/java/nl/requios/effortlessbuilding/helper/RenderHelper.java b/src/main/java/nl/requios/effortlessbuilding/helper/RenderHelper.java index 4162366..fe216eb 100644 --- a/src/main/java/nl/requios/effortlessbuilding/helper/RenderHelper.java +++ b/src/main/java/nl/requios/effortlessbuilding/helper/RenderHelper.java @@ -171,6 +171,7 @@ public class RenderHelper implements IWorldEventListener { float angle = 2f * ((float) Math.PI) / r.slices; Vec3d relStartVec = new Vec3d(radius, 0, 0); + if (r.slices%4 == 2) relStartVec = relStartVec.rotateYaw(angle / 2f); for (int i = 0; i < r.slices; i++) { Vec3d relNewVec = relStartVec.rotateYaw(angle * i); diff --git a/src/main/java/nl/requios/effortlessbuilding/proxy/ClientProxy.java b/src/main/java/nl/requios/effortlessbuilding/proxy/ClientProxy.java index c298cde..8811508 100644 --- a/src/main/java/nl/requios/effortlessbuilding/proxy/ClientProxy.java +++ b/src/main/java/nl/requios/effortlessbuilding/proxy/ClientProxy.java @@ -122,7 +122,8 @@ public class ClientProxy implements IProxy { //KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.getKeyCode(), false); ItemStack currentItemStack = player.getHeldItem(EnumHand.MAIN_HAND); - if (currentItemStack.getItem() instanceof ItemBlock || currentItemStack.getItem() instanceof ItemRandomizerBag) { + if (currentItemStack.getItem() instanceof ItemBlock || + (currentItemStack.getItem() instanceof ItemRandomizerBag && !player.isSneaking())) { //find position in distance RayTraceResult lookingAt = getLookingAt(player); if (lookingAt != null && lookingAt.typeOfHit == RayTraceResult.Type.BLOCK) {