From fece0e39e27889cb32982d8966e9c3d1d4d13bc8 Mon Sep 17 00:00:00 2001
From: simibubi <31564874+simibubi@users.noreply.github.com>
Date: Wed, 25 Aug 2021 17:21:12 +0200
Subject: [PATCH] Add-ons, behave
- Fixed idle blaze burners sending packets every tick
- Fixed placement indicator rendering behind the crosshair
- Added an Event allowing additional tileentitybehaviour objects to be attached to STEs from outside
---
.../event/TileEntityBehaviourEvent.java | 56 +++++++++++++++++++
.../burner/BlazeBurnerTileEntity.java | 1 -
.../tileEntity/SmartTileEntity.java | 10 +++-
.../utility/placement/PlacementHelpers.java | 7 ++-
4 files changed, 69 insertions(+), 5 deletions(-)
create mode 100644 src/main/java/com/simibubi/create/compat/event/TileEntityBehaviourEvent.java
diff --git a/src/main/java/com/simibubi/create/compat/event/TileEntityBehaviourEvent.java b/src/main/java/com/simibubi/create/compat/event/TileEntityBehaviourEvent.java
new file mode 100644
index 000000000..ad9d14bab
--- /dev/null
+++ b/src/main/java/com/simibubi/create/compat/event/TileEntityBehaviourEvent.java
@@ -0,0 +1,56 @@
+package com.simibubi.create.compat.event;
+
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import com.simibubi.create.foundation.tileEntity.SmartTileEntity;
+import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
+import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType;
+
+import net.minecraft.block.BlockState;
+import net.minecraftforge.eventbus.api.GenericEvent;
+
+/**
+ * Event that is fired just before a SmartTileEntity is being deserealized
+ * Also if a new one is placed
+ * Use it to attach a new {@link TileEntityBehaviour} or replace existing ones (with caution)
+ *
+ * Actual setup of the behaviours internal workings and data should be done in TileEntityBehaviour#read() and TileEntityBehaviour#initialize() respectively.
+ *
+ * Because of the earlyness of this event, the added behaviours will have access to the initial nbt read (unless the TE was placed, not loaded), thereby allowing tiles to store and retrieve data for injected behaviours
+ */
+public class TileEntityBehaviourEvent extends GenericEvent {
+
+ private BlockState state;
+ private T smartTileEntity;
+ private Map, TileEntityBehaviour> behaviours;
+
+ public TileEntityBehaviourEvent(BlockState state, T tileEntity,
+ Map, TileEntityBehaviour> behaviours) {
+ this.state = state;
+ smartTileEntity = tileEntity;
+ this.behaviours = behaviours;
+ }
+
+ @Override
+ public Type getGenericType() {
+ return smartTileEntity.getClass();
+ }
+
+ public void attach(TileEntityBehaviour behaviour) {
+ behaviours.put(behaviour.getType(), behaviour);
+ }
+
+ public TileEntityBehaviour remove(BehaviourType> type) {
+ return behaviours.remove(type);
+ }
+
+ public T getTileEntity() {
+ return smartTileEntity;
+ }
+
+ public BlockState getBlockState() {
+ return state;
+ }
+
+}
diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerTileEntity.java
index edd70defc..876e91a60 100644
--- a/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerTileEntity.java
+++ b/src/main/java/com/simibubi/create/content/contraptions/processing/burner/BlazeBurnerTileEntity.java
@@ -95,7 +95,6 @@ public class BlazeBurnerTileEntity extends SmartTileEntity {
activeFuel = FuelType.NONE;
updateBlockState();
- notifyUpdate();
}
private void tickRotation() {
diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java
index b4ec0bc2c..80f5a0fda 100644
--- a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java
+++ b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java
@@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
+import com.simibubi.create.compat.event.TileEntityBehaviourEvent;
import com.simibubi.create.content.schematics.ItemRequirement;
import com.simibubi.create.foundation.gui.IInteractionChecker;
import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType;
@@ -17,6 +18,7 @@ import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.world.World;
+import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.items.CapabilityItemHandler;
@@ -73,6 +75,12 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements ITicka
}
public void initialize() {
+ if (firstNbtRead) {
+ firstNbtRead = false;
+ MinecraftForge.EVENT_BUS.post(new TileEntityBehaviourEvent<>(getBlockState(), this, behaviours));
+ updateBehaviorList();
+ }
+
behaviourList.forEach(TileEntityBehaviour::initialize);
lazyTick();
}
@@ -108,7 +116,7 @@ public abstract class SmartTileEntity extends SyncedTileEntity implements ITicka
ArrayList list = new ArrayList<>();
addBehavioursDeferred(list);
list.forEach(b -> behaviours.put(b.getType(), b));
-
+ MinecraftForge.EVENT_BUS.post(new TileEntityBehaviourEvent<>(state, this, behaviours));
updateBehaviorList();
}
super.load(state, compound);
diff --git a/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementHelpers.java b/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementHelpers.java
index 1bb88d18d..25903ef46 100644
--- a/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementHelpers.java
+++ b/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementHelpers.java
@@ -145,7 +145,7 @@ public class PlacementHelpers {
@SubscribeEvent
@OnlyIn(Dist.CLIENT)
- public static void onRender(RenderGameOverlayEvent.Pre event) {
+ public static void onRender(RenderGameOverlayEvent.Post event) {
if (event.getType() != RenderGameOverlayEvent.ElementType.CROSSHAIRS)
return;
@@ -217,7 +217,7 @@ public class PlacementHelpers {
RenderSystem.defaultBlendFunc();
RenderSystem.shadeModel(GL11.GL_SMOOTH);
- ms.translate(centerX, centerY, 0);
+ ms.translate(centerX, centerY, 5);
ms.mulPose(Vector3f.ZP.rotationDegrees(angle.get(0)));
//RenderSystem.rotatef(snappedAngle, 0, 0, 1);
double scale = AllConfigs.CLIENT.indicatorScale.get();
@@ -252,11 +252,12 @@ public class PlacementHelpers {
RenderSystem.enableTexture();
AllGuiTextures.PLACEMENT_INDICATOR_SHEET.bind();
RenderSystem.enableBlend();
+ RenderSystem.enableDepthTest();
RenderSystem.enableAlphaTest();
RenderSystem.defaultBlendFunc();
RenderSystem.shadeModel(GL11.GL_SMOOTH);
- ms.translate(centerX, centerY, 0);
+ ms.translate(centerX, centerY, 50);
float scale = AllConfigs.CLIENT.indicatorScale.get().floatValue() * .75f;
ms.scale(scale, scale, 1);
ms.scale(12, 12, 1);