From 7b5a5fbcbe0f7a978117b17ce942350a19a6c59b Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Fri, 8 Jul 2016 21:14:55 -0500 Subject: [PATCH] Add ability for custom detector rail output --- .../block/BlockRailDetector.java.patch | 11 ++++ .../event/ForgeEventFactory.java | 9 +++ .../world/DetectorRailComparatorEvent.java | 59 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 patches/minecraft/net/minecraft/block/BlockRailDetector.java.patch create mode 100644 src/main/java/net/minecraftforge/event/world/DetectorRailComparatorEvent.java diff --git a/patches/minecraft/net/minecraft/block/BlockRailDetector.java.patch b/patches/minecraft/net/minecraft/block/BlockRailDetector.java.patch new file mode 100644 index 0000000000..a502ddb6ed --- /dev/null +++ b/patches/minecraft/net/minecraft/block/BlockRailDetector.java.patch @@ -0,0 +1,11 @@ +--- ../src-base/minecraft/net/minecraft/block/BlockRailDetector.java ++++ ../src-work/minecraft/net/minecraft/block/BlockRailDetector.java +@@ -156,6 +156,8 @@ + { + if (((Boolean)p_180641_1_.func_177229_b(field_176574_M)).booleanValue()) + { ++ int result = net.minecraftforge.event.ForgeEventFactory.onDetectorRailCompare(p_180641_3_, func_176572_a(p_180641_3_)); ++ if (result > -1) return result; + List list = this.func_176571_a(p_180641_2_, p_180641_3_, EntityMinecartCommandBlock.class, new Predicate[0]); + + if (!list.isEmpty()) diff --git a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java index eead4dfdc2..40512e3d11 100644 --- a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java +++ b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -46,6 +46,7 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; @@ -101,6 +102,7 @@ import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent.MultiPlaceEvent; import net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent; import net.minecraftforge.event.world.BlockEvent.PlaceEvent; +import net.minecraftforge.event.world.DetectorRailComparatorEvent; import net.minecraftforge.event.world.ExplosionEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; @@ -585,4 +587,11 @@ public class ForgeEventFactory return event.getTable(); } + public static int onDetectorRailCompare(BlockPos pos, AxisAlignedBB box) + { + DetectorRailComparatorEvent evt = new DetectorRailComparatorEvent(pos, box); + MinecraftForge.EVENT_BUS.post(evt); + return evt.getRedstonePower(); + } + } diff --git a/src/main/java/net/minecraftforge/event/world/DetectorRailComparatorEvent.java b/src/main/java/net/minecraftforge/event/world/DetectorRailComparatorEvent.java new file mode 100644 index 0000000000..6848a6c8cf --- /dev/null +++ b/src/main/java/net/minecraftforge/event/world/DetectorRailComparatorEvent.java @@ -0,0 +1,59 @@ +package net.minecraftforge.event.world; + +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.common.eventhandler.Event; + +/** + * This event is fired serverside whenever a Detector Rail looks for a minecart to get a comparator value from + * in {@link net.minecraft.block.BlockRailDetector#getComparatorInputOverride}. + * This event is not cancelable. + * This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}. + */ +public class DetectorRailComparatorEvent extends Event +{ + + private final BlockPos pos; + private final AxisAlignedBB searchBox; + private int redstonePower; + + public DetectorRailComparatorEvent(BlockPos pos, AxisAlignedBB searchBox) + { + this.pos = pos; + this.searchBox = searchBox; + this.redstonePower = -1; + } + + /** + * @return The position of the Detector Rail + */ + public BlockPos getPos() + { + return pos; + } + + /** + * @return The bounding box that is to be searched for minecarts + */ + public AxisAlignedBB getSearchBox() + { + return searchBox; + } + + /** + * @return The redstone signal strength to give the comparator. Values below 0 mean vanilla logic will run. + */ + public int getRedstonePower() + { + return redstonePower; + } + + /** + * Set the redstone power to give the comparator. Values below 0 mean vanilla logic will run. + */ + public void setRedstonePower(int redstonePower) + { + this.redstonePower = redstonePower; + } + +}