Ritual Reader Quality of Life (#1528)

* Groundwork for Reader part 1

* More Ritual Reader information & more intuitive to use.

* Added `getCurrentRitual()` to `IMasterRitualStone`
RitualReader can now only be used on MRS with a set Ritual (this prevents a (caught) NPE).

* Refactored

* Added Enum
This commit is contained in:
Tobias Gremeyer 2019-02-01 02:11:32 +01:00 committed by Nick Ignoffo
parent 95d99c0a01
commit e8eb44632d
7 changed files with 74 additions and 29 deletions

View file

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

View file

@ -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);
}
}

View file

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

View file

@ -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();
}
}

View file

@ -55,7 +55,7 @@ public interface IMasterRitualStone {
void setActiveWillConfig(EntityPlayer player, List<EnumDemonWillType> typeList);
boolean setBlockRangeByBounds(EntityPlayer player, String range, BlockPos offset1, BlockPos offset2);
EnumReaderBoundaries setBlockRangeByBounds(EntityPlayer player, String range, BlockPos offset1, BlockPos offset2);
List<EnumDemonWillType> getActiveWillConfig();
@ -68,4 +68,6 @@ public interface IMasterRitualStone {
void addBlockRanges(Map<String, AreaDescriptor> blockRanges);
void addBlockRange(String range, AreaDescriptor defaultRange);
Ritual getCurrentRitual();
}

View file

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

View file

@ -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<EnumDemonWillType> 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<String, AreaDescriptor> blockRanges){
public void addBlockRanges(Map<String, AreaDescriptor> blockRanges) {
for (Map.Entry<String, AreaDescriptor> entry : blockRanges.entrySet()) {
modableRangeMap.put(entry.getKey(), entry.getValue());
}
}
public boolean checkBlockRanges(Map<String, AreaDescriptor> blockRanges){
public boolean checkBlockRanges(Map<String, AreaDescriptor> blockRanges) {
for (Map.Entry<String, AreaDescriptor> entry : blockRanges.entrySet()) {
if (modableRangeMap.get(entry.getKey()) == null)
return false;