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
This commit is contained in:
Tobias 2019-09-05 03:58:45 +02:00 committed by Nick Ignoffo
parent a23cd35556
commit 1155be6d6b
4 changed files with 75 additions and 9 deletions

View file

@ -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)) {

View file

@ -35,6 +35,8 @@ public abstract class AreaDescriptor implements Iterator<BlockPos> {
}
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<BlockPos> {
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<BlockPos> getContainedPositions(BlockPos pos) {
if (!cache || !pos.equals(cachedPosition) || blockPosCache.isEmpty()) {
@ -122,6 +132,14 @@ public abstract class AreaDescriptor implements Iterator<BlockPos> {
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<BlockPos> {
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<BlockPos> {
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;

View file

@ -71,5 +71,9 @@ public interface IMasterRitualStone {
void addBlockRange(String range, AreaDescriptor defaultRange);
void setBlockRanges(Map<String, AreaDescriptor> blockRanges);
void setBlockRange(String range, AreaDescriptor defaultRange);
Ritual getCurrentRitual();
}

View file

@ -32,6 +32,7 @@ import javax.annotation.Nullable;
import java.util.*;
public class TileMasterRitualStone extends TileTicking implements IMasterRitualStone {
protected final Map<String, AreaDescriptor> 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<EnumDemonWillType> currentActiveWillConfig = new ArrayList<>();
protected final Map<String, AreaDescriptor> 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<String, AreaDescriptor> blockRanges) {
for (Map.Entry<String, AreaDescriptor> 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<String, AreaDescriptor> blockRanges) {
for (Map.Entry<String, AreaDescriptor> entry : blockRanges.entrySet()) {
modableRangeMap.put(entry.getKey(), entry.getValue().copy());
}
}