Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

Commit

Permalink
Ritual Reader Quality of Life (WayofTime#1528)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Tobias Gremeyer authored and TehNut committed Feb 1, 2019
1 parent 95d99c0 commit e8eb446
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 28 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 31 additions & 5 deletions src/main/java/WayofTime/bloodmagic/item/ItemRitualReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -20,6 +21,7 @@
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;
Expand Down Expand Up @@ -90,6 +92,8 @@ public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos
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);

Expand All @@ -99,7 +103,8 @@ public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos
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);
Expand Down Expand Up @@ -136,16 +141,37 @@ public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
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;
Expand All @@ -26,7 +22,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;

@Mod.EventBusSubscriber(modid = BloodMagic.MODID)
public class PotionEventHandlers {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -68,4 +68,6 @@ default SoulTicket ticket(int amount) {
void addBlockRanges(Map<String, AreaDescriptor> blockRanges);

void addBlockRange(String range, AreaDescriptor defaultRange);

Ritual getCurrentRitual();
}
7 changes: 3 additions & 4 deletions src/main/java/WayofTime/bloodmagic/ritual/Ritual.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +15,6 @@

import java.util.*;
import java.util.Map.Entry;
import java.util.function.BiFunction;
import java.util.function.Consumer;

/**
Expand Down Expand Up @@ -186,13 +185,13 @@ public String getNextBlockRange(String range) {
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) {
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/WayofTime/bloodmagic/tile/TileMasterRitualStone.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand Down Expand Up @@ -159,7 +160,7 @@ public boolean activateRitual(ItemStack activationCrystal, @Nullable EntityPlaye
this.cachedNetwork = network;
this.currentRitual = ritual;

if(!checkBlockRanges(ritual.getModableRangeMap()))
if (!checkBlockRanges(ritual.getModableRangeMap()))
addBlockRanges(ritual.getModableRangeMap());

notifyUpdate();
Expand Down Expand Up @@ -188,10 +189,10 @@ public void performRitual(World world, BlockPos pos) {

if (MinecraftForge.EVENT_BUS.post(event))
return;

if (!checkBlockRanges(getCurrentRitual().getModableRangeMap()))
addBlockRanges(getCurrentRitual().getModableRangeMap());

getCurrentRitual().performRitual(this);
} else {
stopRitual(Ritual.BreakType.BREAK_STONE);
Expand Down Expand Up @@ -307,17 +308,17 @@ public void provideInformationOfRangeToPlayer(EntityPlayer player, String range)
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)) {

EnumReaderBoundaries modificationType = currentRitual.canBlockRangeBeModified(range, descriptor, this, offset1, offset2, holder);
if (modificationType == EnumReaderBoundaries.SUCCESS)
descriptor.modifyAreaByBlockPositions(offset1, offset2);
return true;
}

return false;
return modificationType;
}

@Override
Expand Down Expand Up @@ -428,13 +429,13 @@ public void addBlockRange(String range, AreaDescriptor defaultRange) {
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;
Expand Down

0 comments on commit e8eb446

Please sign in to comment.