Some more improvements to the power net.

This commit is contained in:
modmuss50 2017-03-16 13:22:17 +00:00
parent 332fe1be48
commit 056eff09b2
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA
5 changed files with 66 additions and 8 deletions

View file

@ -30,10 +30,12 @@ import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.common.gameevent.TickEvent;
import techreborn.init.ModItems; import techreborn.init.ModItems;
import techreborn.power.PowerDestroyEvent;
import techreborn.power.PowerTickEvent; import techreborn.power.PowerTickEvent;
public class TRTickHandler { public class TRTickHandler {
@ -64,7 +66,9 @@ public class TRTickHandler {
} }
long start = System.nanoTime(); long start = System.nanoTime();
e.world.theProfiler.startSection("TechRebornPowerNet");
MinecraftForge.EVENT_BUS.post(new PowerTickEvent(e.world)); MinecraftForge.EVENT_BUS.post(new PowerTickEvent(e.world));
e.world.theProfiler.endSection();
long elapsed = System.nanoTime() - start; long elapsed = System.nanoTime() - start;
tickTime += elapsed; tickTime += elapsed;
ticksCounted++; ticksCounted++;
@ -76,4 +80,8 @@ public class TRTickHandler {
} }
} }
@SubscribeEvent
public void unload(WorldEvent.Unload event){
MinecraftForge.EVENT_BUS.post(new PowerDestroyEvent(event.getWorld()));
}
} }

View file

@ -410,13 +410,13 @@ public abstract class CableMultipart extends Multipart
} }
} }
if (network == null) { if (network == null) {
network = new TRPowerNet(getCableType()); network = new TRPowerNet(getCableType(), world);
network.addElement(this); network.addElement(this);
} }
for (EnumFacing dir : EnumFacing.VALUES) { for (EnumFacing dir : EnumFacing.VALUES) {
TileEntity te = getNeighbourTile(dir); TileEntity te = getNeighbourTile(dir);
if (te instanceof IEnergyInterfaceTile) { if (te instanceof IEnergyInterfaceTile) {
network.addConnection((IEnergyInterfaceTile) te, dir.getOpposite()); network.addConnection((IEnergyInterfaceTile) te, dir);
} }
} }
} }

View file

@ -0,0 +1,39 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.power;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.Event;
public class PowerDestroyEvent extends Event {
World world;
public PowerDestroyEvent(World world) {
this.world = world;
}
public World getWorld() {
return world;
}
}

View file

@ -28,6 +28,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -45,10 +46,13 @@ public class TRPowerNet {
EnumCableType cableType; EnumCableType cableType;
private ArrayList<CableMultipart> cables = new ArrayList(); private ArrayList<CableMultipart> cables = new ArrayList();
private int energy = 0; private int energy = 0;
private World world;
public TRPowerNet(EnumCableType cableType) {
public TRPowerNet(EnumCableType cableType, World world) {
this.cableType = cableType; this.cableType = cableType;
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
this.world = world;
} }
public static void buildEndpoint(TRPowerNet net) { public static void buildEndpoint(TRPowerNet net) {
@ -83,7 +87,7 @@ public class TRPowerNet {
@SubscribeEvent @SubscribeEvent
public synchronized void tick(PowerTickEvent evt) { public synchronized void tick(PowerTickEvent evt) {
evt.getWorld().theProfiler.startSection("TechRebornPowerNet");
if (tick < 20) { if (tick < 20) {
tick++; tick++;
return; return;
@ -100,6 +104,7 @@ public class TRPowerNet {
it.remove(); it.remove();
} }
} }
buildEndpoint(this);
} }
if (!cables.isEmpty()) { if (!cables.isEmpty()) {
ArrayList<EnergyHandler> collectibles = new ArrayList(); ArrayList<EnergyHandler> collectibles = new ArrayList();
@ -126,7 +131,14 @@ public class TRPowerNet {
MinecraftForge.EVENT_BUS.unregister(this); MinecraftForge.EVENT_BUS.unregister(this);
} }
tick++; tick++;
evt.getWorld().theProfiler.endSection(); }
@SubscribeEvent
public void destory(PowerDestroyEvent event){
if(event.getWorld() == world){
world = null;
MinecraftForge.EVENT_BUS.unregister(this);
}
} }
public void addElement(CableMultipart te) { public void addElement(CableMultipart te) {

View file

@ -129,8 +129,7 @@ public class TileEnergyStorage extends TilePowerAcceptor implements IWrenchable,
@Override @Override
public boolean canAcceptEnergy(EnumFacing direction) { public boolean canAcceptEnergy(EnumFacing direction) {
return getFacing() != direction;
return getFacingEnum() != direction;
} }
@Override @Override