Fixed rotation and various small bugs.

This commit is contained in:
Christian Knaapen
2019-01-10 17:21:56 +01:00
parent aeb4df6156
commit a6d7e0122f
8 changed files with 65 additions and 39 deletions

View File

@@ -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. //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 group = "nl.requios.effortlessbuilding" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "effortlessbuilding" archivesBaseName = "effortlessbuilding"

View File

@@ -85,7 +85,7 @@ public class BuildModifiers {
BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(event.getPlayer()); BuildSettingsManager.BuildSettings buildSettings = BuildSettingsManager.getBuildSettings(event.getPlayer());
//Only use own place event if anything is enabled //Only use own place event if anything is enabled
if (isEnabled(buildSettings, event.getPos())) { if (isEnabled(buildSettings, event.getPos())) {
EffortlessBuilding.packetHandler.sendTo(new BlockPlacedMessage(), (EntityPlayerMP) event.getPlayer()); //EffortlessBuilding.packetHandler.sendTo(new BlockPlacedMessage(), (EntityPlayerMP) event.getPlayer());
event.setCanceled(true); event.setCanceled(true);
} }

View File

@@ -36,7 +36,7 @@ public class EffortlessBuilding
{ {
public static final String MODID = "effortlessbuilding"; public static final String MODID = "effortlessbuilding";
public static final String NAME = "Effortless Building"; 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) @Mod.Instance(EffortlessBuilding.MODID)
public static EffortlessBuilding instance; public static EffortlessBuilding instance;

View File

@@ -67,7 +67,8 @@ public class EventHandler
@SubscribeEvent @SubscribeEvent
public static void onBlockPlaced(BlockEvent.PlaceEvent event) { public static void onBlockPlaced(BlockEvent.PlaceEvent event) {
//BuildModifiers.onBlockPlaced(event); //Still call it to cancel event
BuildModifiers.onBlockPlaced(event);
} }
@SubscribeEvent @SubscribeEvent

View File

@@ -70,8 +70,8 @@ public class RadialMirror {
} }
Vec3d relNewVec = relStartVec.rotateYaw((float) curAngle); Vec3d relNewVec = relStartVec.rotateYaw((float) curAngle);
Vec3d newVec = r.position.add(relNewVec); BlockPos newBlockPos = new BlockPos(r.position.add(relNewVec));
coordinates.add(new BlockPos(newVec)); if (!coordinates.contains(newBlockPos) && !newBlockPos.equals(startPos)) coordinates.add(newBlockPos);
} }
return coordinates; return coordinates;
@@ -79,6 +79,7 @@ public class RadialMirror {
public static List<IBlockState> findBlockStates(EntityPlayer player, BlockPos startPos, IBlockState blockState, ItemStack itemStack, List<ItemStack> itemStacks) { public static List<IBlockState> findBlockStates(EntityPlayer player, BlockPos startPos, IBlockState blockState, ItemStack itemStack, List<ItemStack> itemStacks) {
List<IBlockState> blockStates = new ArrayList<>(); List<IBlockState> blockStates = new ArrayList<>();
List<BlockPos> coordinates = new ArrayList<>(); //to keep track of duplicates
//find radial mirror settings for the player that placed the block //find radial mirror settings for the player that placed the block
RadialMirrorSettings r = BuildSettingsManager.getBuildSettings(player).getRadialMirrorSettings(); RadialMirrorSettings r = BuildSettingsManager.getBuildSettings(player).getRadialMirrorSettings();
@@ -92,17 +93,11 @@ public class RadialMirror {
Vec3d relStartVec = startVec.subtract(r.position); Vec3d relStartVec = startVec.subtract(r.position);
double startAngleToCenter = MathHelper.atan2(relStartVec.x, relStartVec.z); double startAngleToCenter = MathHelper.atan2(relStartVec.x, relStartVec.z);
if (startAngleToCenter < 0) startAngleToCenter += Math.PI; double startAngleToCenterMod = startAngleToCenter < 0 ? startAngleToCenter + Math.PI : startAngleToCenter;
double startAngleInSlice = startAngleToCenter % sliceAngle; double startAngleInSlice = startAngleToCenterMod % sliceAngle;
//Rotate the original blockstate //Rotate the original blockstate
if (startAngleToCenter < -0.75 * Math.PI || startAngleToCenter > 0.75 * Math.PI) { blockState = rotateOriginalBlockState(startAngleToCenter, blockState);
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);
}
//Randomizer bag synergy //Randomizer bag synergy
IItemHandler bagInventory = null; IItemHandler bagInventory = null;
@@ -121,37 +116,20 @@ public class RadialMirror {
} }
Vec3d relNewVec = relStartVec.rotateYaw((float) curAngle); 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 //Randomizer bag synergy
if (bagInventory != null) { if (bagInventory != null) {
itemStack = ItemRandomizerBag.pickRandomStack(bagInventory); itemStack = ItemRandomizerBag.pickRandomStack(bagInventory);
newBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, startPos, EnumFacing.UP, new Vec3d(0, 0, 0), EnumHand.MAIN_HAND); newBlockState = BuildModifiers.getBlockStateFromItem(itemStack, player, startPos, EnumFacing.UP, new Vec3d(0, 0, 0), EnumHand.MAIN_HAND);
newBlockState = rotateOriginalBlockState(startAngleToCenter, newBlockState);
} }
//rotate //rotate
double angleToCenter = MathHelper.atan2(relNewVec.x, relNewVec.z); //between -PI and PI newBlockState = rotateBlockState(relNewVec, newBlockState, r.alternate && i%2 == 1);
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);
}
}
blockStates.add(newBlockState); blockStates.add(newBlockState);
itemStacks.add(itemStack); itemStacks.add(itemStack);
@@ -160,6 +138,49 @@ public class RadialMirror {
return blockStates; 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) { public static boolean isEnabled(RadialMirrorSettings r, BlockPos startPos) {
if (r == null || !r.enabled) return false; if (r == null || !r.enabled) return false;

View File

@@ -89,6 +89,8 @@ public class BuildModifierCapabilityManager {
compound.setInteger("radialMirrorSlices", r.slices); compound.setInteger("radialMirrorSlices", r.slices);
compound.setBoolean("radialMirrorAlternate", r.alternate); compound.setBoolean("radialMirrorAlternate", r.alternate);
compound.setInteger("radialMirrorRadius", r.radius); compound.setInteger("radialMirrorRadius", r.radius);
compound.setBoolean("radialMirrorDrawLines", r.drawLines);
compound.setBoolean("radialMirrorDrawPlanes", r.drawPlanes);
return compound; return compound;
} }

View File

@@ -171,6 +171,7 @@ public class RenderHelper implements IWorldEventListener {
float angle = 2f * ((float) Math.PI) / r.slices; float angle = 2f * ((float) Math.PI) / r.slices;
Vec3d relStartVec = new Vec3d(radius, 0, 0); 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++) { for (int i = 0; i < r.slices; i++) {
Vec3d relNewVec = relStartVec.rotateYaw(angle * i); Vec3d relNewVec = relStartVec.rotateYaw(angle * i);

View File

@@ -122,7 +122,8 @@ public class ClientProxy implements IProxy {
//KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.getKeyCode(), false); //KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.getKeyCode(), false);
ItemStack currentItemStack = player.getHeldItem(EnumHand.MAIN_HAND); 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 //find position in distance
RayTraceResult lookingAt = getLookingAt(player); RayTraceResult lookingAt = getLookingAt(player);
if (lookingAt != null && lookingAt.typeOfHit == RayTraceResult.Type.BLOCK) { if (lookingAt != null && lookingAt.typeOfHit == RayTraceResult.Type.BLOCK) {