mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 03:53:12 +01:00
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
This commit is contained in:
parent
925c98792f
commit
fece0e39e2
4 changed files with 69 additions and 5 deletions
|
@ -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 <br>
|
||||
* Also if a new one is placed<br>
|
||||
* Use it to attach a new {@link TileEntityBehaviour} or replace existing ones (with caution) <br>
|
||||
* <br>
|
||||
* Actual setup of the behaviours internal workings and data should be done in TileEntityBehaviour#read() and TileEntityBehaviour#initialize() respectively.<br>
|
||||
* <br>
|
||||
* 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<T extends SmartTileEntity> extends GenericEvent<T> {
|
||||
|
||||
private BlockState state;
|
||||
private T smartTileEntity;
|
||||
private Map<BehaviourType<?>, TileEntityBehaviour> behaviours;
|
||||
|
||||
public TileEntityBehaviourEvent(BlockState state, T tileEntity,
|
||||
Map<BehaviourType<?>, 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -95,7 +95,6 @@ public class BlazeBurnerTileEntity extends SmartTileEntity {
|
|||
activeFuel = FuelType.NONE;
|
||||
|
||||
updateBlockState();
|
||||
notifyUpdate();
|
||||
}
|
||||
|
||||
private void tickRotation() {
|
||||
|
|
|
@ -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<TileEntityBehaviour> 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue