Fixed rotation and various small bugs.
This commit is contained in:
@@ -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"
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<IBlockState> findBlockStates(EntityPlayer player, BlockPos startPos, IBlockState blockState, ItemStack itemStack, List<ItemStack> itemStacks) {
|
||||
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
|
||||
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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user