diff --git a/gradle.properties b/gradle.properties index 2b89fa29..48dbcb74 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,4 @@ mappings_version=snapshot_20180201 jei_version=4.8.5.147 waila_version=1.8.23-B38_1.12 -guideapi_version=1.12-2.1.4-57 +guideapi_version=1.12-2.1.4-57 \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/item/ItemRitualReader.java b/src/main/java/WayofTime/bloodmagic/item/ItemRitualReader.java index b6f7297d..bceeb86e 100644 --- a/src/main/java/WayofTime/bloodmagic/item/ItemRitualReader.java +++ b/src/main/java/WayofTime/bloodmagic/item/ItemRitualReader.java @@ -4,6 +4,7 @@ import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.client.IVariantProvider; import WayofTime.bloodmagic.ritual.EnumRitualReaderState; import WayofTime.bloodmagic.ritual.IMasterRitualStone; +import WayofTime.bloodmagic.ritual.Ritual; import WayofTime.bloodmagic.soul.EnumDemonWillType; import WayofTime.bloodmagic.soul.IDiscreteDemonWill; import WayofTime.bloodmagic.util.ChatUtil; @@ -20,6 +21,7 @@ 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; @@ -90,6 +92,8 @@ public class ItemRitualReader extends Item implements IVariantProvider { TileEntity tile = world.getTileEntity(pos); if (tile instanceof IMasterRitualStone) { IMasterRitualStone master = (IMasterRitualStone) tile; + if (master.getCurrentRitual() == null) + super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ); this.setMasterBlockPos(stack, pos); this.setBlockPos(stack, BlockPos.ORIGIN); @@ -99,7 +103,8 @@ public class ItemRitualReader extends Item implements IVariantProvider { break; case SET_AREA: String range = this.getCurrentBlockRange(stack); - if (player.isSneaking()) { + + if (range == null || player.isSneaking()) { String newRange = master.getNextBlockRange(range); range = newRange; this.setCurrentBlockRange(stack, newRange); @@ -136,16 +141,37 @@ public class ItemRitualReader extends Item implements IVariantProvider { if (!masterPos.equals(BlockPos.ORIGIN)) { BlockPos containedPos = getBlockPos(stack); if (containedPos.equals(BlockPos.ORIGIN)) { - this.setBlockPos(stack, pos.subtract(masterPos)); + BlockPos pos1 = pos.subtract(masterPos); + this.setBlockPos(stack, pos1); player.sendStatusMessage(new TextComponentTranslation("ritual.bloodmagic.blockRange.firstBlock"), true); - //TODO: Notify player. + player.sendMessage(new TextComponentString(pos1.toString())); } else { tile = world.getTileEntity(masterPos); if (tile instanceof IMasterRitualStone) { IMasterRitualStone master = (IMasterRitualStone) tile; - master.setBlockRangeByBounds(player, this.getCurrentBlockRange(stack), containedPos, pos.subtract(masterPos)); - } + BlockPos pos2 = pos.subtract(masterPos); + String range = this.getCurrentBlockRange(stack); + 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 maxVolume = ritual.getMaxVolumeForRange(range, null, null); + switch (master.setBlockRangeByBounds(player, range, containedPos, pos2)) { + case SUCCESS: + player.sendStatusMessage(new TextComponentTranslation("ritual.bloodmagic.blockRange.success"), true); + break; + case NOT_WITHIN_BOUNDARIES: + player.sendStatusMessage(new TextComponentTranslation("ritual.bloodmagic.blockRange.tooFar", maxVerticalRange, maxHorizontalRange), false); + break; + case VOLUME_TOO_LARGE: + player.sendStatusMessage(new TextComponentTranslation("ritual.bloodmagic.blockRange.tooBig", maxVolume), false); + break; + default: + player.sendStatusMessage(new TextComponentTranslation("ritual.bloodmagic.blockRange.noRange"), false); + break; + } + } this.setBlockPos(stack, BlockPos.ORIGIN); } } diff --git a/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java b/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java index 57f68fc2..46b12fc1 100644 --- a/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java +++ b/src/main/java/WayofTime/bloodmagic/potion/PotionEventHandlers.java @@ -13,11 +13,7 @@ import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.World; -import net.minecraftforge.event.entity.living.EnderTeleportEvent; -import net.minecraftforge.event.entity.living.LivingAttackEvent; -import net.minecraftforge.event.entity.living.LivingDamageEvent; -import net.minecraftforge.event.entity.living.LivingEvent; -import net.minecraftforge.event.entity.living.LivingFallEvent; +import net.minecraftforge.event.entity.living.*; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.EventPriority; @@ -26,7 +22,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.ArrayList; @Mod.EventBusSubscriber(modid = BloodMagic.MODID) public class PotionEventHandlers { diff --git a/src/main/java/WayofTime/bloodmagic/ritual/EnumReaderBoundaries.java b/src/main/java/WayofTime/bloodmagic/ritual/EnumReaderBoundaries.java new file mode 100644 index 00000000..0f69f17c --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/ritual/EnumReaderBoundaries.java @@ -0,0 +1,22 @@ +package WayofTime.bloodmagic.ritual; + +import net.minecraft.util.IStringSerializable; + +import java.util.Locale; + +public enum EnumReaderBoundaries implements IStringSerializable { + SUCCESS, + VOLUME_TOO_LARGE, + NOT_WITHIN_BOUNDARIES; + + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } + + @Override + public String getName() { + return toString(); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/ritual/IMasterRitualStone.java b/src/main/java/WayofTime/bloodmagic/ritual/IMasterRitualStone.java index 8f338258..6ed5924b 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/IMasterRitualStone.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/IMasterRitualStone.java @@ -55,7 +55,7 @@ public interface IMasterRitualStone { void setActiveWillConfig(EntityPlayer player, List typeList); - boolean setBlockRangeByBounds(EntityPlayer player, String range, BlockPos offset1, BlockPos offset2); + EnumReaderBoundaries setBlockRangeByBounds(EntityPlayer player, String range, BlockPos offset1, BlockPos offset2); List getActiveWillConfig(); @@ -68,4 +68,6 @@ public interface IMasterRitualStone { void addBlockRanges(Map blockRanges); void addBlockRange(String range, AreaDescriptor defaultRange); + + Ritual getCurrentRitual(); } diff --git a/src/main/java/WayofTime/bloodmagic/ritual/Ritual.java b/src/main/java/WayofTime/bloodmagic/ritual/Ritual.java index 7e642e6c..95504bce 100644 --- a/src/main/java/WayofTime/bloodmagic/ritual/Ritual.java +++ b/src/main/java/WayofTime/bloodmagic/ritual/Ritual.java @@ -1,8 +1,8 @@ package WayofTime.bloodmagic.ritual; +import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; import WayofTime.bloodmagic.soul.DemonWillHolder; import WayofTime.bloodmagic.soul.EnumDemonWillType; -import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -15,7 +15,6 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import java.util.*; import java.util.Map.Entry; -import java.util.function.BiFunction; import java.util.function.Consumer; /** @@ -186,13 +185,13 @@ public abstract class Ritual { return rangeList.get(0); } - public boolean canBlockRangeBeModified(String range, AreaDescriptor descriptor, IMasterRitualStone master, BlockPos offset1, BlockPos offset2, DemonWillHolder holder) { + public EnumReaderBoundaries canBlockRangeBeModified(String range, AreaDescriptor descriptor, IMasterRitualStone master, BlockPos offset1, BlockPos offset2, DemonWillHolder holder) { List willConfig = master.getActiveWillConfig(); int maxVolume = getMaxVolumeForRange(range, willConfig, holder); int maxVertical = getMaxVerticalRadiusForRange(range, willConfig, holder); int maxHorizontal = getMaxHorizontalRadiusForRange(range, willConfig, holder); - return (maxVolume <= 0 || descriptor.getVolumeForOffsets(offset1, offset2) <= maxVolume) && descriptor.isWithinRange(offset1, offset2, maxVertical, maxHorizontal); + return (maxVolume <= 0 || descriptor.getVolumeForOffsets(offset1, offset2) <= maxVolume) ? descriptor.isWithinRange(offset1, offset2, maxVertical, maxHorizontal) ? EnumReaderBoundaries.SUCCESS : EnumReaderBoundaries.NOT_WITHIN_BOUNDARIES : EnumReaderBoundaries.VOLUME_TOO_LARGE; } protected void setMaximumVolumeAndDistanceOfRange(String range, int volume, int horizontalRadius, int verticalRadius) { diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java b/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java index e27f53b4..1f803f26 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java @@ -9,6 +9,7 @@ import WayofTime.bloodmagic.event.RitualEvent; import WayofTime.bloodmagic.iface.IBindable; import WayofTime.bloodmagic.item.ItemActivationCrystal; import WayofTime.bloodmagic.ritual.AreaDescriptor; +import WayofTime.bloodmagic.ritual.EnumReaderBoundaries; import WayofTime.bloodmagic.ritual.IMasterRitualStone; import WayofTime.bloodmagic.ritual.Ritual; import WayofTime.bloodmagic.soul.DemonWillHolder; @@ -159,7 +160,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS this.cachedNetwork = network; this.currentRitual = ritual; - if(!checkBlockRanges(ritual.getModableRangeMap())) + if (!checkBlockRanges(ritual.getModableRangeMap())) addBlockRanges(ritual.getModableRangeMap()); notifyUpdate(); @@ -188,10 +189,10 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS if (MinecraftForge.EVENT_BUS.post(event)) return; - + if (!checkBlockRanges(getCurrentRitual().getModableRangeMap())) addBlockRanges(getCurrentRitual().getModableRangeMap()); - + getCurrentRitual().performRitual(this); } else { stopRitual(Ritual.BreakType.BREAK_STONE); @@ -307,17 +308,17 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS public void setActiveWillConfig(EntityPlayer player, List typeList) { this.currentActiveWillConfig = typeList; } - + @Override - public boolean setBlockRangeByBounds(EntityPlayer player, String range, BlockPos offset1, BlockPos offset2) { + public EnumReaderBoundaries setBlockRangeByBounds(EntityPlayer player, String range, BlockPos offset1, BlockPos offset2) { AreaDescriptor descriptor = this.getBlockRange(range); DemonWillHolder holder = WorldDemonWillHandler.getWillHolder(world, getBlockPos()); - if (this.currentRitual.canBlockRangeBeModified(range, descriptor, this, offset1, offset2, holder)) { - descriptor.modifyAreaByBlockPositions(offset1, offset2); - return true; - } - return false; + EnumReaderBoundaries modificationType = currentRitual.canBlockRangeBeModified(range, descriptor, this, offset1, offset2, holder); + if (modificationType == EnumReaderBoundaries.SUCCESS) + descriptor.modifyAreaByBlockPositions(offset1, offset2); + + return modificationType; } @Override @@ -428,13 +429,13 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS modableRangeMap.put(range, defaultRange); } - public void addBlockRanges(Map blockRanges){ + public void addBlockRanges(Map blockRanges) { for (Map.Entry entry : blockRanges.entrySet()) { modableRangeMap.put(entry.getKey(), entry.getValue()); } } - public boolean checkBlockRanges(Map blockRanges){ + public boolean checkBlockRanges(Map blockRanges) { for (Map.Entry entry : blockRanges.entrySet()) { if (modableRangeMap.get(entry.getKey()) == null) return false;