Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
5aab6ecf88
9 changed files with 62 additions and 31 deletions
20
common/buildcraft/core/utils/MathUtils.java
Normal file
20
common/buildcraft/core/utils/MathUtils.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.core.utils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class MathUtils {
|
||||
|
||||
public static double clamp(double value, double min, double max) {
|
||||
return value < min ? min : (value > max ? max : value);
|
||||
}
|
||||
}
|
|
@ -609,6 +609,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
|
|||
|
||||
if (isValid(pipe)) {
|
||||
pipe.container.scheduleNeighborChange();
|
||||
pipe.container.redstonePowered = world.isBlockIndirectlyGettingPowered(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ public abstract class Gate {
|
|||
boolean[] oldBroadcastSignal = broadcastSignal;
|
||||
|
||||
broadcastRedstone = false;
|
||||
broadcastSignal = new boolean[]{false, false, false, false};
|
||||
broadcastSignal = new boolean[4];
|
||||
|
||||
// Tell the gate to prepare for resolving actions. (Disable pulser)
|
||||
startResolution();
|
||||
|
|
|
@ -67,6 +67,13 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
|
|||
transport.setTile((TileGenericPipe) tile);
|
||||
}
|
||||
|
||||
// public final void handlePipeEvent(PipeEvent event) {
|
||||
// try {
|
||||
// Method method = getClass().getDeclaredMethod("eventHandler", event.getClass());
|
||||
// method.invoke(this, event);
|
||||
// } catch (Exception ex) {
|
||||
// }
|
||||
// }
|
||||
private static class EventHandler {
|
||||
|
||||
public final Method method;
|
||||
|
@ -83,15 +90,8 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
|
|||
eventHandlers.put(getClass(), handlerMap);
|
||||
}
|
||||
EventHandler handler = handlerMap.get(event.getClass());
|
||||
if (handler == null) {
|
||||
try {
|
||||
Method method = getClass().getDeclaredMethod("eventHandler", event.getClass());
|
||||
handler = new EventHandler(method);
|
||||
} catch (Exception ex) {
|
||||
handler = new EventHandler(null);
|
||||
}
|
||||
handlerMap.put(event.getClass(), handler);
|
||||
}
|
||||
if (handler == null)
|
||||
handler = makeEventHandler(event, handlerMap);
|
||||
if (handler.method == null)
|
||||
return;
|
||||
try {
|
||||
|
@ -100,6 +100,18 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
|
|||
}
|
||||
}
|
||||
|
||||
private EventHandler makeEventHandler(PipeEvent event, Map<Class<? extends PipeEvent>, EventHandler> handlerMap) {
|
||||
EventHandler handler;
|
||||
try {
|
||||
Method method = getClass().getDeclaredMethod("eventHandler", event.getClass());
|
||||
handler = new EventHandler(method);
|
||||
} catch (Exception ex) {
|
||||
handler = new EventHandler(null);
|
||||
}
|
||||
handlerMap.put(event.getClass(), handler);
|
||||
return handler;
|
||||
}
|
||||
|
||||
public boolean blockActivated(EntityPlayer entityplayer) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import buildcraft.core.network.PacketIds;
|
|||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.BCLog;
|
||||
import buildcraft.core.utils.BlockUtil;
|
||||
import buildcraft.core.utils.MathUtils;
|
||||
import buildcraft.transport.network.PacketPipeTransportContent;
|
||||
import buildcraft.transport.network.PacketPipeTransportNBT;
|
||||
import buildcraft.transport.network.PacketSimpleId;
|
||||
|
@ -33,12 +34,12 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
|
@ -47,6 +48,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class PipeTransportItems extends PipeTransport {
|
||||
|
@ -151,17 +153,9 @@ public class PipeTransportItems extends PipeTransport {
|
|||
}
|
||||
|
||||
private void readjustPosition(TravelingItem item) {
|
||||
double x = item.xCoord;
|
||||
double y = item.yCoord;
|
||||
double z = item.zCoord;
|
||||
|
||||
x = Math.max(x, container.xCoord + 0.01);
|
||||
y = Math.max(y, container.yCoord + 0.01);
|
||||
z = Math.max(z, container.zCoord + 0.01);
|
||||
|
||||
x = Math.min(x, container.xCoord + 0.99);
|
||||
y = Math.min(y, container.yCoord + 0.99);
|
||||
z = Math.min(z, container.zCoord + 0.99);
|
||||
double x = MathUtils.clamp(item.xCoord, container.xCoord + 0.01, container.xCoord + 0.99);
|
||||
double y = MathUtils.clamp(item.yCoord, container.yCoord + 0.01, container.yCoord + 0.99);
|
||||
double z = MathUtils.clamp(item.zCoord, container.zCoord + 0.01, container.zCoord + 0.99);
|
||||
|
||||
if (item.input != ForgeDirection.UP && item.input != ForgeDirection.DOWN) {
|
||||
y = container.yCoord + TransportUtils.getPipeFloorOf(item.getItemStack());
|
||||
|
@ -284,9 +278,10 @@ public class PipeTransportItems extends PipeTransport {
|
|||
|
||||
item.blacklist.add(item.input.getOpposite());
|
||||
|
||||
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (item.blacklist.contains(o))
|
||||
continue;
|
||||
EnumSet<ForgeDirection> sides = EnumSet.complementOf(item.blacklist);
|
||||
sides.remove(ForgeDirection.UNKNOWN);
|
||||
|
||||
for (ForgeDirection o : sides) {
|
||||
if (container.pipe.outputOpen(o) && canReceivePipeObjects(o, item))
|
||||
result.add(o);
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
|
|||
private boolean blockNeighborChange = false;
|
||||
private boolean refreshRenderState = false;
|
||||
private boolean pipeBound = false;
|
||||
public boolean redstonePowered = false;
|
||||
private int[] facadeBlocks = new int[ForgeDirection.VALID_DIRECTIONS.length];
|
||||
private int[] facadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length];
|
||||
private boolean[] plugs = new boolean[ForgeDirection.VALID_DIRECTIONS.length];
|
||||
|
@ -99,6 +100,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
|
|||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setBoolean("redstonePowered", redstonePowered);
|
||||
|
||||
if (pipe != null) {
|
||||
nbt.setInteger("pipeId", pipe.itemID);
|
||||
|
@ -117,7 +119,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
|
|||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
redstonePowered = nbt.getBoolean("redstonePowered");
|
||||
|
||||
coreState.pipeId = nbt.getInteger("pipeId");
|
||||
pipe = BlockGenericPipe.createPipe(coreState.pipeId);
|
||||
|
||||
|
|
|
@ -36,9 +36,9 @@ public class PipeItemsGold extends Pipe {
|
|||
return PipeIconProvider.TYPE.PipeItemsGold.ordinal();
|
||||
}
|
||||
|
||||
public void handleEvent(PipeEventItem.AdjustSpeed event) {
|
||||
public void eventHandler(PipeEventItem.AdjustSpeed event) {
|
||||
event.handled = true;
|
||||
TravelingItem item = event.item;
|
||||
item.setSpeed(Math.min(Math.max(TransportConstants.PIPE_NORMAL_SPEED, item.getSpeed()) * 2f, TransportConstants.PIPE_NORMAL_SPEED * 20F));
|
||||
item.setSpeed(Math.min(Math.max(TransportConstants.PIPE_NORMAL_SPEED, item.getSpeed()) * 4f, TransportConstants.PIPE_NORMAL_SPEED * 20F));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,11 +34,11 @@ public class PipeItemsVoid extends Pipe<PipeTransportItems> {
|
|||
return PipeIconProvider.TYPE.PipeItemsVoid.ordinal();
|
||||
}
|
||||
|
||||
public void handleEvent(PipeEventItem.DropItem event) {
|
||||
public void eventHandler(PipeEventItem.DropItem event) {
|
||||
event.entity = null;
|
||||
}
|
||||
|
||||
public void handleEvent(PipeEventItem.ReachedCenter event) {
|
||||
public void eventHandler(PipeEventItem.ReachedCenter event) {
|
||||
transport.items.scheduleRemoval(event.item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class TriggerRedstoneInput extends BCTrigger implements ITriggerPipe {
|
|||
}
|
||||
|
||||
private boolean isBeingPowered(Pipe pipe) {
|
||||
return pipe.container.worldObj.isBlockIndirectlyGettingPowered(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
|
||||
return pipe.container.redstonePowered;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue