From 1155be6d6bfc286404f1e6a96e3109a5f29c7ade Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 5 Sep 2019 03:58:45 +0200 Subject: [PATCH] Fixed Ritual Tinkerer & added range reset (#1636) * Add getMinimumOffset() and getMaximumOffset to AreaDescriptor Add the ability to reset BlockRanges to the Ritual Tinkerer * Added copy-constructors and functions to AreaDescriptor Added the ability to reset BlockRanges to the Ritual Tinkerer - Mode: Define Area, with BloodOrb in offhand & sneaking, right click on MRS Changed "addBlockRange" and "addBlockRanges" to use .putIfAbsent Added "setBlockRange" and "setBlockRanges" to IMasterRitualStone - reference implementation in TileMasterRitualStone is identical to old "addBlockRange" and "addBlockRanges" Fixed range setting for good. Tested behavior with RitualWater. * Minor cleanup * Remove TODO --- .../bloodmagic/item/ItemRitualReader.java | 26 ++++++++++---- .../bloodmagic/ritual/AreaDescriptor.java | 34 +++++++++++++++++++ .../bloodmagic/ritual/IMasterRitualStone.java | 4 +++ .../tile/TileMasterRitualStone.java | 20 +++++++++-- 4 files changed, 75 insertions(+), 9 deletions(-) diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemRitualReader.java b/src/main/java/WayofTime/bloodmagic/item/ItemRitualReader.java index f96afc24..6358762a 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemRitualReader.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemRitualReader.java @@ -2,6 +2,7 @@ package WayofTime.bloodmagic.item; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.client.IVariantProvider; +import WayofTime.bloodmagic.ritual.AreaDescriptor; import WayofTime.bloodmagic.ritual.EnumRitualReaderState; import WayofTime.bloodmagic.ritual.IMasterRitualStone; import WayofTime.bloodmagic.ritual.Ritual; @@ -21,7 +22,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.*; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; @@ -100,11 +100,21 @@ public class ItemRitualReader extends Item implements IVariantProvider { switch (state) { case INFORMATION: master.provideInformationOfRitualToPlayer(player); + break; case SET_AREA: + if (player.isSneaking() && player.getHeldItem(EnumHand.OFF_HAND).getItem() instanceof ItemBloodOrb) { + Ritual ritual = master.getCurrentRitual(); + for (String range : ritual.getListOfRanges()) { + AreaDescriptor aabb = ritual.getBlockRange(range); + master.setBlockRange(range, aabb); + } + break; + } + String range = this.getCurrentBlockRange(stack); - if (range == null || player.isSneaking()) { + if (range == null || range.isEmpty() || player.isSneaking()) { String newRange = master.getNextBlockRange(range); range = newRange; this.setCurrentBlockRange(stack, newRange); @@ -144,17 +154,21 @@ public class ItemRitualReader extends Item implements IVariantProvider { BlockPos pos1 = pos.subtract(masterPos); this.setBlockPos(stack, pos1); player.sendStatusMessage(new TextComponentTranslation("ritual.bloodmagic.blockRange.firstBlock"), true); - player.sendMessage(new TextComponentString(pos1.toString())); } else { tile = world.getTileEntity(masterPos); if (tile instanceof IMasterRitualStone) { IMasterRitualStone master = (IMasterRitualStone) tile; BlockPos pos2 = pos.subtract(masterPos); String range = this.getCurrentBlockRange(stack); + if (range == null || range.isEmpty()) { + String newRange = master.getNextBlockRange(range); + range = newRange; + this.setCurrentBlockRange(stack, newRange); + } Ritual ritual = master.getCurrentRitual(); - //TODO: Fix AreaDescriptor area handling to be inclusive, then remove the "-1" for range calculation below. - int maxHorizontalRange = ritual.getMaxHorizontalRadiusForRange(range, null, null) - 1; - int maxVerticalRange = ritual.getMaxVerticalRadiusForRange(range, null, null) - 1; + + int maxHorizontalRange = ritual.getMaxHorizontalRadiusForRange(range, null, null); + int maxVerticalRange = ritual.getMaxVerticalRadiusForRange(range, null, null); int maxVolume = ritual.getMaxVolumeForRange(range, null, null); switch (master.setBlockRangeByBounds(player, range, containedPos, pos2)) { diff --git a/src/main/java/WayofTime/bloodmagic/ritual/AreaDescriptor.java b/src/main/java/WayofTime/bloodmagic/ritual/AreaDescriptor.java index b6f5dc83..e51a062d 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/AreaDescriptor.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/AreaDescriptor.java @@ -35,6 +35,8 @@ public abstract class AreaDescriptor implements Iterator { } + public abstract AreaDescriptor copy(); + public abstract int getVolumeForOffsets(BlockPos offset1, BlockPos offset2); public abstract boolean isWithinRange(BlockPos offset1, BlockPos offset2, int verticalLimit, int horizontalLimit); @@ -91,6 +93,14 @@ public abstract class AreaDescriptor implements Iterator { this(minimumOffset, size, size, size); } + public Rectangle(AreaDescriptor.Rectangle rectangle) { + this(rectangle.minimumOffset, rectangle.maximumOffset); + } + + public AreaDescriptor.Rectangle copy() { + return new AreaDescriptor.Rectangle(this); + } + @Override public List getContainedPositions(BlockPos pos) { if (!cache || !pos.equals(cachedPosition) || blockPosCache.isEmpty()) { @@ -122,6 +132,14 @@ public abstract class AreaDescriptor implements Iterator { return this.maximumOffset.getY() - this.minimumOffset.getY(); } + public BlockPos getMinimumOffset() { + return minimumOffset; + } + + public BlockPos getMaximumOffset() { + return maximumOffset; + } + /** * Sets the offsets of the AreaDescriptor in a safe way that will make * minimumOffset the lowest corner @@ -271,6 +289,14 @@ public abstract class AreaDescriptor implements Iterator { setRadius(minimumOffset, radius); } + public HemiSphere(AreaDescriptor.HemiSphere hemiSphere) { + this(hemiSphere.minimumOffset, hemiSphere.radius); + } + + public AreaDescriptor.HemiSphere copy() { + return new AreaDescriptor.HemiSphere(this); + } + public void setRadius(BlockPos minimumOffset, int radius) { this.minimumOffset = new BlockPos(Math.min(minimumOffset.getX(), minimumOffset.getX()), Math.min(minimumOffset.getY(), minimumOffset.getY()), Math.min(minimumOffset.getZ(), minimumOffset.getZ())); this.radius = radius; @@ -417,6 +443,14 @@ public abstract class AreaDescriptor implements Iterator { this.blockPosCache = new ArrayList<>(); } + public Cross(AreaDescriptor.Cross cross) { + this(cross.centerPos, cross.size); + } + + public AreaDescriptor.Cross copy() { + return new AreaDescriptor.Cross(this); + } + @Override public int getHeight() { return this.size * 2 + 1; diff --git a/src/main/java/WayofTime/bloodmagic/ritual/IMasterRitualStone.java b/src/main/java/WayofTime/bloodmagic/ritual/IMasterRitualStone.java index 1ce20d8b..1ba75a6f 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/IMasterRitualStone.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/IMasterRitualStone.java @@ -71,5 +71,9 @@ public interface IMasterRitualStone { void addBlockRange(String range, AreaDescriptor defaultRange); + void setBlockRanges(Map blockRanges); + + void setBlockRange(String range, AreaDescriptor defaultRange); + Ritual getCurrentRitual(); } diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java b/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java index 46e6332d..88ae398b 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java @@ -32,6 +32,7 @@ import javax.annotation.Nullable; import java.util.*; public class TileMasterRitualStone extends TileTicking implements IMasterRitualStone { + protected final Map modableRangeMap = new HashMap<>(); private UUID owner; private SoulNetwork cachedNetwork; private boolean active; @@ -42,7 +43,6 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS private EnumFacing direction = EnumFacing.NORTH; private boolean inverted; private List currentActiveWillConfig = new ArrayList<>(); - protected final Map modableRangeMap = new HashMap<>(); @Override public void onUpdate() { @@ -425,13 +425,27 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS return null; } + @Override public void addBlockRange(String range, AreaDescriptor defaultRange) { - modableRangeMap.put(range, defaultRange); + modableRangeMap.putIfAbsent(range, defaultRange.copy()); } + @Override public void addBlockRanges(Map blockRanges) { for (Map.Entry entry : blockRanges.entrySet()) { - modableRangeMap.put(entry.getKey(), entry.getValue()); + modableRangeMap.putIfAbsent(entry.getKey(), entry.getValue().copy()); + } + } + + @Override + public void setBlockRange(String range, AreaDescriptor defaultRange) { + modableRangeMap.put(range, defaultRange.copy()); + } + + @Override + public void setBlockRanges(Map blockRanges) { + for (Map.Entry entry : blockRanges.entrySet()) { + modableRangeMap.put(entry.getKey(), entry.getValue().copy()); } }