Cleanup event classes more and fix dedicated server crash (#49)

This commit is contained in:
Alexdoru authored and GitHub committed 2026-02-26 10:45:18 +01:00
1 parent 5d732d18f3
commit 3f6c6cb236
10 files changed
+258 -248

No files matched your search

@@ -79,6 +79,7 @@ import makeo.gadomancy.common.blocks.tiles.TileRemoteJar;
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
import makeo.gadomancy.common.entities.EntityAuraCore;
import makeo.gadomancy.common.entities.EntityPermNoClipItem;
import makeo.gadomancy.common.events.EventHandlerTooltips;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.registration.RegisteredItems;
import makeo.gadomancy.common.utils.Injector;
@@ -95,7 +96,7 @@ import thaumcraft.common.tiles.TileEldritchObelisk;
/**
* This class is part of the Gadomancy Mod Gadomancy is Open Source and distributed under the GNU LESSER GENERAL PUBLIC
* LICENSE for more read the LICENSE file
*
* <p>
* Created by makeo @ 29.11.2014 14:15
*/
public class ClientProxy extends CommonProxy {
@@ -227,15 +228,15 @@ public class ClientProxy extends CommonProxy {
@Override
public void postInitalize() {
IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
if (manager instanceof SimpleReloadableResourceManager) {
SimpleReloadableResourceManager rm = (SimpleReloadableResourceManager) manager;
if (manager instanceof SimpleReloadableResourceManager rm) {
rm.registerReloadListener(ResourceReloadListener.getInstance());
}
MinecraftForge.EVENT_BUS.register(new EventHandlerTooltips());
MinecraftForge.EVENT_BUS.register(EffectHandler.getInstance());
MinecraftForge.EVENT_BUS.register(new RenderEventHandler());
FMLCommonHandler.instance().bus().register(new RenderEventHandler());
final RenderEventHandler renderHandler = new RenderEventHandler();
MinecraftForge.EVENT_BUS.register(renderHandler);
FMLCommonHandler.instance().bus().register(renderHandler);
FMLCommonHandler.instance().bus().register(new ClientHandler());
super.postInitalize();
@@ -1,6 +1,5 @@
package makeo.gadomancy.client.events;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.zip.GZIPInputStream;
@@ -60,21 +59,39 @@ import thaumcraft.common.items.wands.ItemWandCasting;
/**
* This class is part of the Gadomancy Mod Gadomancy is Open Source and distributed under the GNU LESSER GENERAL PUBLIC
* LICENSE for more read the LICENSE file
*
* <p>
* Created by makeo @ 13.10.2015 16:11
*/
public class RenderEventHandler {
public final class RenderEventHandler {
private static final REHWandHandler WAND_HANDLER = new REHWandHandler();
private static final FakeArchitectItem ARCHITECT_ITEM = new FakeArchitectItem();
private static final IModelCustom obj;
private static final ResourceLocation texture = new ResourceLocation("gadomancy:textures/misc/texW.png");
static {
ResourceLocation resourceLocation = new ResourceLocation("gadomancy:textures/models/modelAssec.obj");
IModelCustom buf;
try {
buf = new WavefrontObject(
"gadomancy:wRender",
new GZIPInputStream(
Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation)
.getInputStream()));
} catch (Exception exc) {
// shush.
buf = null;
}
obj = buf;
}
private final REHWandHandler WAND_HANDLER = new REHWandHandler();
private final FakeArchitectItem ARCHITECT_ITEM = new FakeArchitectItem();
private Object oldGolemblurb;
private int blurbId;
private int dList = -1;
@SubscribeEvent
public void on(GuiScreenEvent.DrawScreenEvent.Pre e) {
if (e.gui instanceof GuiGolem) {
GuiGolem gui = (GuiGolem) e.gui;
if (e.gui instanceof GuiGolem gui) {
EntityGolemBase golem = new Injector(gui, GuiGolem.class).getField("golem");
if (golem != null) {
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
@@ -103,13 +120,13 @@ public class RenderEventHandler {
if (e.currentItem == null) return;
if (e.currentItem.getItem() instanceof ItemWandCasting) {
ItemFocusBasic focus = ((ItemWandCasting) e.currentItem.getItem()).getFocus(e.currentItem);
if (focus == null || !(focus instanceof IArchitect)) {
if (!(focus instanceof IArchitect)) {
Block block = e.player.worldObj.getBlock(e.target.blockX, e.target.blockY, e.target.blockZ);
if (block != null && block == RegisteredBlocks.blockArcaneDropper) {
ForgeDirection dir = ForgeDirection.getOrientation(
e.player.worldObj.getBlockMetadata(e.target.blockX, e.target.blockY, e.target.blockZ) & 7);
ArrayList<BlockCoordinates> coords = new ArrayList<BlockCoordinates>();
ArrayList<BlockCoordinates> coords = new ArrayList<>();
for (int x = -1; x < 2; x++) {
for (int y = -1; y < 2; y++) {
for (int z = -1; z < 2; z++) {
@@ -127,11 +144,11 @@ public class RenderEventHandler {
e.target.blockY + dir.offsetY,
e.target.blockZ + dir.offsetZ));
RenderEventHandler.ARCHITECT_ITEM.setCoords(coords);
this.ARCHITECT_ITEM.setCoords(coords);
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
RenderEventHandler.WAND_HANDLER.handleArchitectOverlay(
new ItemStack(RenderEventHandler.ARCHITECT_ITEM),
this.WAND_HANDLER.handleArchitectOverlay(
new ItemStack(this.ARCHITECT_ITEM),
e,
e.player.ticksExisted,
e.target);
@@ -145,13 +162,11 @@ public class RenderEventHandler {
int blockZ = e.target.blockZ;
if (Minecraft.getMinecraft().gameSettings.thirdPersonView == 0) {
TileEntity tile = e.player.worldObj.getTileEntity(blockX, blockY, blockZ);
if (tile instanceof TileExtendedNode) {
TileExtendedNode node = (TileExtendedNode) tile;
if (tile instanceof TileExtendedNode node) {
if (node.getExtendedNodeType() == null) return;
ExtendedTypeDisplayManager
.notifyDisplayTick(node.getId(), node.getNodeType(), node.getExtendedNodeType());
} else if (tile instanceof TileExtendedNodeJar) {
TileExtendedNodeJar nodeJar = (TileExtendedNodeJar) tile;
} else if (tile instanceof TileExtendedNodeJar nodeJar) {
if (nodeJar.getExtendedNodeType() == null) return;
ExtendedTypeDisplayManager
.notifyDisplayTick(nodeJar.getId(), nodeJar.getNodeType(), nodeJar.getExtendedNodeType());
@@ -162,8 +177,7 @@ public class RenderEventHandler {
@SubscribeEvent
public void guiOpen(GuiOpenEvent event) {
if (event.gui != null && event.gui instanceof GuiResearchRecipe) {
GuiResearchRecipe gui = (GuiResearchRecipe) event.gui;
if (event.gui instanceof GuiResearchRecipe gui) {
ResearchItem research = new Injector(gui, GuiResearchRecipe.class).getField("research");
if (research.key.equals(Gadomancy.MODID.toUpperCase() + ".AURA_EFFECTS")
&& !(gui instanceof GuiResearchRecipeAuraEffects)) {
@@ -183,10 +197,8 @@ public class RenderEventHandler {
@SubscribeEvent(priority = EventPriority.LOWEST)
public void renderEntityPre(RenderLivingEvent.Pre event) {
if (event.entity instanceof EntityPlayer) {
EntityPlayer p = (EntityPlayer) event.entity;
if (((DataAchromatic) SyncDataHolder.getDataClient("AchromaticData"))
.isAchromatic((EntityPlayer) event.entity)) {
if (event.entity instanceof EntityPlayer p) {
if (((DataAchromatic) SyncDataHolder.getDataClient("AchromaticData")).isAchromatic(p)) {
this.current = p;
GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.15F);
GL11.glDepthMask(false);
@@ -224,8 +236,7 @@ public class RenderEventHandler {
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void renderPost(RenderLivingEvent.Post event) {
if (event.entity instanceof EntityPlayer) {
EntityPlayer p = (EntityPlayer) event.entity;
if (event.entity instanceof EntityPlayer p) {
if (this.armor != null) {
p.inventory.armorInventory = this.armor;
}
@@ -241,33 +252,6 @@ public class RenderEventHandler {
}
}
static {
ResourceLocation mod = new ResourceLocation(
Gadomancy.MODID.toLowerCase() + new String(
new byte[] { 58, 116, 101, 120, 116, 117, 114, 101, 115, 47, 109, 111, 100, 101, 108, 115, 47,
109, 111, 100, 101, 108, 65, 115, 115, 101, 99, 46, 111, 98, 106 },
StandardCharsets.UTF_8));
IModelCustom buf;
try {
buf = new WavefrontObject(
"gadomancy:wRender",
new GZIPInputStream(
Minecraft.getMinecraft().getResourceManager().getResource(mod).getInputStream()));
} catch (Exception exc) {
// shush.
buf = null;
}
obj = buf;
}
private static final IModelCustom obj;
private static final ResourceLocation tex = new ResourceLocation(
new String(
new byte[] { 103, 97, 100, 111, 109, 97, 110, 99, 121, 58, 116, 101, 120, 116, 117, 114, 101, 115,
47, 109, 105, 115, 99, 47, 116, 101, 120, 87, 46, 112, 110, 103 },
StandardCharsets.UTF_8));
private static int dList = -1;
@SubscribeEvent
public void onRender(RenderPlayerEvent.Specials.Post event) {
if (event.entityPlayer == null) return;
@@ -278,7 +262,7 @@ public class RenderEventHandler {
GL11.glColor4f(1f, 1f, 1f, 1f);
GL11.glPushMatrix();
Minecraft.getMinecraft().renderEngine.bindTexture(RenderEventHandler.tex);
Minecraft.getMinecraft().renderEngine.bindTexture(RenderEventHandler.texture);
boolean f = event.entityPlayer.capabilities.isFlying;
double ma = f ? 15 : 5;
double r = (ma * (Math.abs((ClientHandler.ticks % 80) - 40) / 40D)) + ((65 - ma) * Math
@@ -286,22 +270,22 @@ public class RenderEventHandler {
GL11.glScaled(0.07, 0.07, 0.07);
GL11.glRotatef(180, 0, 0, 1);
GL11.glTranslated(0, -12.7, 0.7 - (((float) (r / ma)) * (f ? 0.5D : 0.2D)));
if (RenderEventHandler.dList == -1) {
RenderEventHandler.dList = GLAllocation.generateDisplayLists(2);
GL11.glNewList(RenderEventHandler.dList, GL11.GL_COMPILE);
if (this.dList == -1) {
this.dList = GLAllocation.generateDisplayLists(2);
GL11.glNewList(this.dList, GL11.GL_COMPILE);
RenderEventHandler.obj.renderOnly("wR");
GL11.glEndList();
GL11.glNewList(RenderEventHandler.dList + 1, GL11.GL_COMPILE);
GL11.glNewList(this.dList + 1, GL11.GL_COMPILE);
RenderEventHandler.obj.renderOnly("wL");
GL11.glEndList();
}
GL11.glPushMatrix();
GL11.glRotated(20D + r, 0, -1, 0);
GL11.glCallList(RenderEventHandler.dList);
GL11.glCallList(this.dList);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glRotated(20D + r, 0, 1, 0);
GL11.glCallList(RenderEventHandler.dList + 1);
GL11.glCallList(this.dList + 1);
GL11.glPopMatrix();
GL11.glPopMatrix();
}
@@ -22,8 +22,9 @@ import makeo.gadomancy.common.containers.ContainerArcanePackager;
import makeo.gadomancy.common.containers.ContainerInfusionClaw;
import makeo.gadomancy.common.data.SyncDataHolder;
import makeo.gadomancy.common.data.config.ModConfig;
import makeo.gadomancy.common.events.EventHandlerEntity;
import makeo.gadomancy.common.events.EventHandlerEntityServer;
import makeo.gadomancy.common.events.EventHandlerGolem;
import makeo.gadomancy.common.events.EventHandlerGolemServer;
import makeo.gadomancy.common.events.EventHandlerNetwork;
import makeo.gadomancy.common.events.EventHandlerWorld;
import makeo.gadomancy.common.network.PacketHandler;
@@ -72,6 +73,8 @@ public class CommonProxy implements IGuiHandler {
RegisteredEntities.init();
DimensionManager.registerProviderType(ModConfig.dimOuterId, WorldProviderTCEldrich.class, true);
DimensionManager.registerDimension(ModConfig.dimOuterId, ModConfig.dimOuterId);
FMLCommonHandler.instance().bus().register(new EventHandlerNetwork());
MinecraftForge.EVENT_BUS.register(new EventHandlerGolem());
}
public void postInitalize() {
@@ -126,32 +129,27 @@ public class CommonProxy implements IGuiHandler {
return Side.SERVER;
}
public EventHandlerGolem EVENT_HANDLER_GOLEM;
public EventHandlerNetwork EVENT_HANDLER_NETWORK;
public EventHandlerWorld EVENT_HANDLER_WORLD;
public EventHandlerEntity EVENT_HANDLER_ENTITY;
public EventHandlerGolemServer handlerGolemServer;
private EventHandlerWorld handlerWorld;
public EventHandlerEntityServer handlerEntityServer;
public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
EVENT_HANDLER_GOLEM = new EventHandlerGolem();
MinecraftForge.EVENT_BUS.register(EVENT_HANDLER_GOLEM);
EVENT_HANDLER_NETWORK = new EventHandlerNetwork();
FMLCommonHandler.instance().bus().register(EVENT_HANDLER_NETWORK);
EVENT_HANDLER_WORLD = new EventHandlerWorld();
MinecraftForge.EVENT_BUS.register(EVENT_HANDLER_WORLD);
FMLCommonHandler.instance().bus().register(EVENT_HANDLER_WORLD);
EVENT_HANDLER_ENTITY = new EventHandlerEntity();
MinecraftForge.EVENT_BUS.register(EVENT_HANDLER_ENTITY);
handlerGolemServer = new EventHandlerGolemServer();
MinecraftForge.EVENT_BUS.register(handlerGolemServer);
handlerWorld = new EventHandlerWorld();
MinecraftForge.EVENT_BUS.register(handlerWorld);
FMLCommonHandler.instance().bus().register(handlerWorld);
handlerEntityServer = new EventHandlerEntityServer();
MinecraftForge.EVENT_BUS.register(handlerEntityServer);
}
public void onServerStopped(FMLServerStoppedEvent event) {
MinecraftForge.EVENT_BUS.unregister(EVENT_HANDLER_GOLEM);
EVENT_HANDLER_GOLEM = null;
FMLCommonHandler.instance().bus().unregister(EVENT_HANDLER_NETWORK);
EVENT_HANDLER_NETWORK = null;
MinecraftForge.EVENT_BUS.unregister(EVENT_HANDLER_WORLD);
FMLCommonHandler.instance().bus().unregister(EVENT_HANDLER_WORLD);
EVENT_HANDLER_WORLD = null;
MinecraftForge.EVENT_BUS.unregister(EVENT_HANDLER_ENTITY);
EVENT_HANDLER_ENTITY = null;
MinecraftForge.EVENT_BUS.unregister(handlerGolemServer);
handlerGolemServer = null;
MinecraftForge.EVENT_BUS.unregister(handlerWorld);
FMLCommonHandler.instance().bus().unregister(handlerWorld);
handlerWorld = null;
MinecraftForge.EVENT_BUS.unregister(handlerEntityServer);
handlerEntityServer = null;
}
}
@@ -201,8 +201,8 @@ public class AuraEffects {
@Override
public void doEntityEffect(ChunkCoordinates originTile, Entity e) {
if (!Gadomancy.proxy.EVENT_HANDLER_ENTITY.registeredLuxPylons.contains(originTile)) {
Gadomancy.proxy.EVENT_HANDLER_ENTITY.registeredLuxPylons.add(originTile);
if (!Gadomancy.proxy.handlerEntityServer.registeredLuxPylons.contains(originTile)) {
Gadomancy.proxy.handlerEntityServer.registeredLuxPylons.add(originTile);
}
}
@@ -36,7 +36,7 @@ import thaumcraft.common.items.armor.Hover;
* <p/>
* Created by HellFirePvP @ 31.10.2015 15:28
*/
public class EventHandlerEntity {
public class EventHandlerEntityServer {
public final List<ChunkCoordinates> registeredLuxPylons = new ArrayList<>();
@@ -91,8 +91,7 @@ public class EventHandlerEntity {
@SubscribeEvent
public void on(EntityItemPickupEvent event) {
if (!event.entityPlayer.worldObj.isRemote) {
if (event.item instanceof EntityPermNoClipItem) {
EntityPermNoClipItem item = (EntityPermNoClipItem) event.item;
if (event.item instanceof EntityPermNoClipItem item) {
ChunkCoordinates master = (ChunkCoordinates) item.getDataWatcher()
.getWatchedObject(ModConfig.entityNoClipItemDatawatcherMasterId).getObject();
TileEntity te = event.entityPlayer.worldObj.getTileEntity(master.posX, master.posY, master.posZ);
@@ -1,23 +1,14 @@
package makeo.gadomancy.common.events;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
@@ -25,7 +16,6 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.api.golems.events.GolemDropPlacerEvent;
import makeo.gadomancy.api.golems.events.PlacerCreateGolemEvent;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.data.DataAchromatic;
@@ -45,28 +35,22 @@ import thaumcraft.common.items.wands.ItemWandCasting;
/**
* This class is part of the Gadomancy Mod Gadomancy is Open Source and distributed under the GNU LESSER GENERAL PUBLIC
* LICENSE for more read the LICENSE file
*
* <p>
* Created by makeo @ 13.03.2015 13:56
*/
public class EventHandlerGolem {
private final Map<EntityGolemBase, EntityPlayer> markedGolems = new HashMap<>();
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(EntityEvent.EntityConstructing e) {
if (e.entity instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) e.entity;
if (e.entity instanceof EntityGolemBase golem) {
golem.registerExtendedProperties(Gadomancy.MODID, new ExtendedGolemProperties(golem));
golem.getDataWatcher().addObject(ModConfig.golemDatawatcherId, "");
}
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void on(EntityEvent.EnteringChunk event) {
if (event.entity instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) event.entity;
if (event.entity instanceof EntityGolemBase golem) {
if (GadomancyApi.isAdditionalGolemType(golem.getGolemType())) {
ExtendedGolemProperties props = (ExtendedGolemProperties) event.entity
.getExtendedProperties(Gadomancy.MODID);
@@ -80,18 +64,15 @@ public class EventHandlerGolem {
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void on(EntityJoinWorldEvent event) {
if (!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) event.entity;
if (!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase golem) {
ExtendedGolemProperties props = (ExtendedGolemProperties) golem.getExtendedProperties(Gadomancy.MODID);
if (props != null) {
props.setWrapperIfNeeded();
}
}
if (event.entity instanceof EntityItem) {
EntityItem item = (EntityItem) event.entity;
if (event.entity instanceof EntityItem item) {
ItemStack stack = item.getEntityItem();
if (stack.getItem() == ConfigItems.itemGolemPlacer) {
AdditionalGolemType type = GadomancyApi
.getAdditionalGolemType(EnumGolemType.getType(stack.getItemDamage()));
@@ -124,8 +105,7 @@ public class EventHandlerGolem {
.onItemUseFirst(itemInHand, e.entityPlayer, e.world, e.x, e.y, e.z, e.face, 0, 0, 0)) {
e.setCanceled(true);
Entity entity = e.world.getEntityByID(entityId);
if (entity != null && entity instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) entity;
if (entity instanceof EntityGolemBase golem) {
// move persistent data to entity
golem.getEntityData().setTag(Gadomancy.MODID, NBTHelper.getPersistentData(itemInHand).copy());
@@ -149,74 +129,14 @@ public class EventHandlerGolem {
}
}
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void on(PlaySoundAtEntityEvent event) {
if (!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase
&& event.name.equals("thaumcraft:zap")
&& event.volume == 0.5F
&& event.pitch == 1.0F) {
EntityGolemBase golem = (EntityGolemBase) event.entity;
if (this.markedGolems.containsKey(golem)) {
EntityPlayer player = this.markedGolems.get(golem);
this.markedGolems.remove(golem);
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
boolean movedPlacer = false;
boolean movedCore = core == null || !player.isSneaking();
for (EntityItem entityItem : golem.capturedDrops) {
ItemStack item = entityItem.getEntityItem();
if (!movedCore && item.getItem() == ConfigItems.itemGolemCore) {
entityItem.setEntityItemStack(core.getItem());
}
if (!movedPlacer && item.getItem() instanceof ItemGolemPlacer
|| item.getItem() instanceof ItemAdditionalGolemPlacer) {
// move persistent data to item
NBTTagCompound persistent = (NBTTagCompound) NBTHelper.getPersistentData(golem).copy();
if (player.isSneaking()) {
persistent.removeTag("Core");
}
NBTHelper.getData(item).setTag(Gadomancy.MODID, persistent);
event.entity.setDead();
entityItem.setEntityItemStack(item);
MinecraftForge.EVENT_BUS.post(new GolemDropPlacerEvent(player, entityItem, golem));
movedPlacer = true;
}
event.entity.worldObj.spawnEntityInWorld(entityItem);
}
golem.capturedDrops.clear();
golem.captureDrops = false;
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(AttackEntityEvent event) {
ItemStack heldItem = event.entityPlayer.getHeldItem();
if (heldItem != null && heldItem.getItem() == ConfigItems.itemGolemBell
&& event.target instanceof EntityGolemBase
&& !event.target.worldObj.isRemote
&& !event.target.isDead) {
event.target.captureDrops = true;
this.markedGolems.put((EntityGolemBase) event.target, event.entityPlayer);
}
}
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(LivingHurtEvent event) {
if (!event.entity.worldObj.isRemote) {
if (event.entity instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) event.entity;
if (event.entity instanceof EntityGolemBase golem) {
if (event.ammount > 0 && RegisteredGolemStuff.upgradeRunicShield.hasUpgrade(golem)) {
event.ammount = RegisteredGolemStuff.upgradeRunicShield.absorb(golem, event.ammount, event.source);
}
}
/*
* if(event.source.getEntity() != null && event.source.getEntity() instanceof EntityGolemBase &&
* ((EntityGolemBase) event.source.getEntity()).getGolemType() ==
@@ -229,8 +149,7 @@ public class EventHandlerGolem {
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(EntityInteractEvent event) {
ItemStack heldItem = event.entityPlayer.getHeldItem();
if (event.target instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) event.target;
if (event.target instanceof EntityGolemBase golem) {
if (golem.getCore() < 0) {
if (heldItem != null) {
@@ -275,36 +194,4 @@ public class EventHandlerGolem {
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(ItemTooltipEvent event) {
if (event.itemStack != null) {
if (event.itemStack.getItem() instanceof ItemGolemPlacer
|| event.itemStack.getItem() instanceof ItemAdditionalGolemPlacer) {
if (RegisteredGolemStuff.upgradeRunicShield.hasUpgrade(event.itemStack)) {
event.toolTip.add(
"\u00a76" + StatCollector.translateToLocal("item.runic.charge")
+ " +"
+ RegisteredGolemStuff.upgradeRunicShield.getChargeLimit(event.itemStack));
}
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(event.itemStack);
if (core != null) {
String searchStr = StatCollector.translateToLocal("item.ItemGolemCore.name");
for (int i = 0; i < event.toolTip.size(); i++) {
String line = event.toolTip.get(i);
if (line.contains(searchStr)) {
int index = line.indexOf('\u00a7', searchStr.length()) + 2;
event.toolTip.remove(i);
event.toolTip.add(
i,
line.substring(0, index)
+ StatCollector.translateToLocal(core.getUnlocalizedName()));
break;
}
}
}
}
}
}
}
@@ -0,0 +1,86 @@
package makeo.gadomancy.common.events;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.api.golems.events.GolemDropPlacerEvent;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.entities.golems.ItemAdditionalGolemPlacer;
import makeo.gadomancy.common.utils.NBTHelper;
import thaumcraft.common.config.ConfigItems;
import thaumcraft.common.entities.golems.EntityGolemBase;
import thaumcraft.common.entities.golems.ItemGolemPlacer;
public class EventHandlerGolemServer {
private final Map<EntityGolemBase, EntityPlayer> markedGolems = new HashMap<>();
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void on(PlaySoundAtEntityEvent event) {
if (!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase golem
&& event.name.equals("thaumcraft:zap")
&& event.volume == 0.5F
&& event.pitch == 1.0F) {
if (this.markedGolems.containsKey(golem)) {
EntityPlayer player = this.markedGolems.get(golem);
this.markedGolems.remove(golem);
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
boolean movedPlacer = false;
boolean movedCore = core == null || !player.isSneaking();
for (EntityItem entityItem : golem.capturedDrops) {
ItemStack item = entityItem.getEntityItem();
if (!movedCore && item.getItem() == ConfigItems.itemGolemCore) {
entityItem.setEntityItemStack(core.getItem());
}
if (!movedPlacer && item.getItem() instanceof ItemGolemPlacer
|| item.getItem() instanceof ItemAdditionalGolemPlacer) {
// move persistent data to item
NBTTagCompound persistent = (NBTTagCompound) NBTHelper.getPersistentData(golem).copy();
if (player.isSneaking()) {
persistent.removeTag("Core");
}
NBTHelper.getData(item).setTag(Gadomancy.MODID, persistent);
event.entity.setDead();
entityItem.setEntityItemStack(item);
MinecraftForge.EVENT_BUS.post(new GolemDropPlacerEvent(player, entityItem, golem));
movedPlacer = true;
}
event.entity.worldObj.spawnEntityInWorld(entityItem);
}
golem.capturedDrops.clear();
golem.captureDrops = false;
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(AttackEntityEvent event) {
ItemStack heldItem = event.entityPlayer.getHeldItem();
if (heldItem != null && heldItem.getItem() == ConfigItems.itemGolemBell
&& event.target instanceof EntityGolemBase
&& !event.target.worldObj.isRemote
&& !event.target.isDead) {
event.target.captureDrops = true;
this.markedGolems.put((EntityGolemBase) event.target, event.entityPlayer);
}
}
}
@@ -0,0 +1,82 @@
package makeo.gadomancy.common.events;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.common.entities.golems.ItemAdditionalGolemPlacer;
import makeo.gadomancy.common.registration.RegisteredGolemStuff;
import makeo.gadomancy.common.utils.NBTHelper;
import thaumcraft.common.entities.golems.ItemGolemPlacer;
public class EventHandlerTooltips {
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on1(ItemTooltipEvent e) {
if (!e.toolTip.isEmpty() && e.itemStack.hasTagCompound()) {
if (e.itemStack.stackTagCompound.getBoolean("isStickyJar")) {
e.toolTip.add(1, EnumChatFormatting.GREEN + StatCollector.translateToLocal("gadomancy.lore.stickyjar"));
}
}
if (!e.toolTip.isEmpty() && NBTHelper.hasPersistentData(e.itemStack)) {
NBTTagCompound compound = NBTHelper.getPersistentData(e.itemStack);
if (compound.hasKey("disguise")) {
NBTBase base = compound.getTag("disguise");
String lore = null;
if (base instanceof NBTTagCompound) {
ItemStack stack = ItemStack.loadItemStackFromNBT((NBTTagCompound) base);
if (stack != null) {
lore = String.format(
StatCollector.translateToLocal("gadomancy.lore.disguise.item"),
EnumChatFormatting.getTextWithoutFormattingCodes(stack.getDisplayName()));
}
} else {
lore = StatCollector.translateToLocal("gadomancy.lore.disguise.none");
}
if (lore != null) {
e.toolTip.add(EnumChatFormatting.GREEN + lore);
}
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on2(ItemTooltipEvent event) {
if (event.itemStack != null) {
if (event.itemStack.getItem() instanceof ItemGolemPlacer
|| event.itemStack.getItem() instanceof ItemAdditionalGolemPlacer) {
if (RegisteredGolemStuff.upgradeRunicShield.hasUpgrade(event.itemStack)) {
event.toolTip.add(
"\u00a76" + StatCollector.translateToLocal("item.runic.charge")
+ " +"
+ RegisteredGolemStuff.upgradeRunicShield.getChargeLimit(event.itemStack));
}
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(event.itemStack);
if (core != null) {
String searchStr = StatCollector.translateToLocal("item.ItemGolemCore.name");
for (int i = 0; i < event.toolTip.size(); i++) {
String line = event.toolTip.get(i);
if (line.contains(searchStr)) {
int index = line.indexOf('\u00a7', searchStr.length()) + 2;
event.toolTip.remove(i);
event.toolTip.add(
i,
line.substring(0, index)
+ StatCollector.translateToLocal(core.getUnlocalizedName()));
break;
}
}
}
}
}
}
}
@@ -17,7 +17,6 @@ import net.minecraft.util.StatCollector;
import net.minecraft.world.Explosion;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.ExplosionEvent;
@@ -62,7 +61,7 @@ public class EventHandlerWorld {
public void on(EntityJoinWorldEvent event) {
if (!event.world.isRemote && event.entity instanceof EntityItem) {
ItemStack stack = ((EntityItem) event.entity).getEntityItem();
if (this.isDisguised(stack)) {
if (isDisguised(stack)) {
long time = event.world.getTotalWorldTime() + event.world.rand.nextInt(60) + 40;
this.trackedItems.put((EntityItem) event.entity, time);
}
@@ -94,7 +93,7 @@ public class EventHandlerWorld {
EntityItem entity = entry.getKey();
if (event.world == entity.worldObj) {
if (entity.isDead || !this.isDisguised(entity.getEntityItem())) {
if (entity.isDead || !isDisguised(entity.getEntityItem())) {
iterator.remove();
continue;
}
@@ -142,7 +141,7 @@ public class EventHandlerWorld {
}
}
private boolean isDisguised(ItemStack stack) {
private static boolean isDisguised(ItemStack stack) {
return NBTHelper.hasPersistentData(stack) && NBTHelper.getPersistentData(stack).hasKey("disguise");
}
@@ -190,7 +189,7 @@ public class EventHandlerWorld {
SyncDataHolder.doNecessaryUpdates();
this.serverTick++;
if ((this.serverTick & 15) == 0) {
Gadomancy.proxy.EVENT_HANDLER_ENTITY.registeredLuxPylons.clear();
Gadomancy.proxy.handlerEntityServer.registeredLuxPylons.clear();
}
}
@@ -199,7 +198,7 @@ public class EventHandlerWorld {
if (e.isCanceled()) {
if (this.interacts != null) this.interacts.remove(e.player);
} else {
if (!e.world.isRemote && this.isStickyJar(e.itemInHand)) {
if (!e.world.isRemote && isStickyJar(e.itemInHand)) {
TileEntity parent = e.world.getTileEntity(e.x, e.y, e.z);
if (parent instanceof TileJarFillable) {
int metadata = e.world.getBlockMetadata(e.x, e.y, e.z);
@@ -252,7 +251,7 @@ public class EventHandlerWorld {
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(PlayerInteractEvent e) {
if (!e.world.isRemote && e.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK
&& this.isStickyJar(e.entityPlayer.getHeldItem())) {
&& isStickyJar(e.entityPlayer.getHeldItem())) {
if (this.interacts == null) {
this.interacts = new HashMap<EntityPlayer, Integer>();
}
@@ -267,34 +266,8 @@ public class EventHandlerWorld {
}
}
private boolean isStickyJar(ItemStack stack) {
private static boolean isStickyJar(ItemStack stack) {
return RegisteredItems.isStickyableJar(stack) && stack.hasTagCompound()
&& stack.stackTagCompound.getBoolean("isStickyJar");
}
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(ItemTooltipEvent e) {
if (!e.toolTip.isEmpty() && e.itemStack.hasTagCompound()) {
if (e.itemStack.stackTagCompound.getBoolean("isStickyJar")) {
e.toolTip.add(1, EnumChatFormatting.GREEN + StatCollector.translateToLocal("gadomancy.lore.stickyjar"));
}
}
if (!e.toolTip.isEmpty() && NBTHelper.hasPersistentData(e.itemStack)) {
NBTTagCompound compound = NBTHelper.getPersistentData(e.itemStack);
if (compound.hasKey("disguise")) {
NBTBase base = compound.getTag("disguise");
String lore;
if (base instanceof NBTTagCompound) {
ItemStack stack = ItemStack.loadItemStackFromNBT((NBTTagCompound) base);
lore = String.format(
StatCollector.translateToLocal("gadomancy.lore.disguise.item"),
EnumChatFormatting.getTextWithoutFormattingCodes(stack.getDisplayName()));
} else {
lore = StatCollector.translateToLocal("gadomancy.lore.disguise.none");
}
e.toolTip.add(EnumChatFormatting.GREEN + lore);
}
}
}
}
@@ -86,7 +86,7 @@ public class IntegrationThaumicHorizions extends IntegrationMod {
ItemStack stack = player.getCurrentEquippedItem();
if (stack != null && stack.getItem().onLeftClickEntity(stack, player, e.target) && e.target.isDead) {
Gadomancy.proxy.EVENT_HANDLER_GOLEM
Gadomancy.proxy.handlerGolemServer
.on(new PlaySoundAtEntityEvent(e.target, "thaumcraft:zap", 0.5f, 1.0f));
}
}