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)) {
|
if (isValid(pipe)) {
|
||||||
pipe.container.scheduleNeighborChange();
|
pipe.container.scheduleNeighborChange();
|
||||||
|
pipe.container.redstonePowered = world.isBlockIndirectlyGettingPowered(x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ public abstract class Gate {
|
||||||
boolean[] oldBroadcastSignal = broadcastSignal;
|
boolean[] oldBroadcastSignal = broadcastSignal;
|
||||||
|
|
||||||
broadcastRedstone = false;
|
broadcastRedstone = false;
|
||||||
broadcastSignal = new boolean[]{false, false, false, false};
|
broadcastSignal = new boolean[4];
|
||||||
|
|
||||||
// Tell the gate to prepare for resolving actions. (Disable pulser)
|
// Tell the gate to prepare for resolving actions. (Disable pulser)
|
||||||
startResolution();
|
startResolution();
|
||||||
|
|
|
@ -67,6 +67,13 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
|
||||||
transport.setTile((TileGenericPipe) tile);
|
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 {
|
private static class EventHandler {
|
||||||
|
|
||||||
public final Method method;
|
public final Method method;
|
||||||
|
@ -83,15 +90,8 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
|
||||||
eventHandlers.put(getClass(), handlerMap);
|
eventHandlers.put(getClass(), handlerMap);
|
||||||
}
|
}
|
||||||
EventHandler handler = handlerMap.get(event.getClass());
|
EventHandler handler = handlerMap.get(event.getClass());
|
||||||
if (handler == null) {
|
if (handler == null)
|
||||||
try {
|
handler = makeEventHandler(event, handlerMap);
|
||||||
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.method == null)
|
if (handler.method == null)
|
||||||
return;
|
return;
|
||||||
try {
|
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) {
|
public boolean blockActivated(EntityPlayer entityplayer) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import buildcraft.core.network.PacketIds;
|
||||||
import buildcraft.core.proxy.CoreProxy;
|
import buildcraft.core.proxy.CoreProxy;
|
||||||
import buildcraft.core.utils.BCLog;
|
import buildcraft.core.utils.BCLog;
|
||||||
import buildcraft.core.utils.BlockUtil;
|
import buildcraft.core.utils.BlockUtil;
|
||||||
|
import buildcraft.core.utils.MathUtils;
|
||||||
import buildcraft.transport.network.PacketPipeTransportContent;
|
import buildcraft.transport.network.PacketPipeTransportContent;
|
||||||
import buildcraft.transport.network.PacketPipeTransportNBT;
|
import buildcraft.transport.network.PacketPipeTransportNBT;
|
||||||
import buildcraft.transport.network.PacketSimpleId;
|
import buildcraft.transport.network.PacketSimpleId;
|
||||||
|
@ -33,12 +34,12 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.inventory.ISidedInventory;
|
import net.minecraft.inventory.ISidedInventory;
|
||||||
|
@ -47,6 +48,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.network.packet.Packet;
|
import net.minecraft.network.packet.Packet;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
public class PipeTransportItems extends PipeTransport {
|
public class PipeTransportItems extends PipeTransport {
|
||||||
|
@ -151,17 +153,9 @@ public class PipeTransportItems extends PipeTransport {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readjustPosition(TravelingItem item) {
|
private void readjustPosition(TravelingItem item) {
|
||||||
double x = item.xCoord;
|
double x = MathUtils.clamp(item.xCoord, container.xCoord + 0.01, container.xCoord + 0.99);
|
||||||
double y = item.yCoord;
|
double y = MathUtils.clamp(item.yCoord, container.yCoord + 0.01, container.yCoord + 0.99);
|
||||||
double z = item.zCoord;
|
double z = MathUtils.clamp(item.zCoord, container.zCoord + 0.01, container.zCoord + 0.99);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (item.input != ForgeDirection.UP && item.input != ForgeDirection.DOWN) {
|
if (item.input != ForgeDirection.UP && item.input != ForgeDirection.DOWN) {
|
||||||
y = container.yCoord + TransportUtils.getPipeFloorOf(item.getItemStack());
|
y = container.yCoord + TransportUtils.getPipeFloorOf(item.getItemStack());
|
||||||
|
@ -284,9 +278,10 @@ public class PipeTransportItems extends PipeTransport {
|
||||||
|
|
||||||
item.blacklist.add(item.input.getOpposite());
|
item.blacklist.add(item.input.getOpposite());
|
||||||
|
|
||||||
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
|
EnumSet<ForgeDirection> sides = EnumSet.complementOf(item.blacklist);
|
||||||
if (item.blacklist.contains(o))
|
sides.remove(ForgeDirection.UNKNOWN);
|
||||||
continue;
|
|
||||||
|
for (ForgeDirection o : sides) {
|
||||||
if (container.pipe.outputOpen(o) && canReceivePipeObjects(o, item))
|
if (container.pipe.outputOpen(o) && canReceivePipeObjects(o, item))
|
||||||
result.add(o);
|
result.add(o);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
|
||||||
private boolean blockNeighborChange = false;
|
private boolean blockNeighborChange = false;
|
||||||
private boolean refreshRenderState = false;
|
private boolean refreshRenderState = false;
|
||||||
private boolean pipeBound = false;
|
private boolean pipeBound = false;
|
||||||
|
public boolean redstonePowered = false;
|
||||||
private int[] facadeBlocks = new int[ForgeDirection.VALID_DIRECTIONS.length];
|
private int[] facadeBlocks = new int[ForgeDirection.VALID_DIRECTIONS.length];
|
||||||
private int[] facadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length];
|
private int[] facadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length];
|
||||||
private boolean[] plugs = new boolean[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
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt) {
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
nbt.setBoolean("redstonePowered", redstonePowered);
|
||||||
|
|
||||||
if (pipe != null) {
|
if (pipe != null) {
|
||||||
nbt.setInteger("pipeId", pipe.itemID);
|
nbt.setInteger("pipeId", pipe.itemID);
|
||||||
|
@ -117,7 +119,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt) {
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
redstonePowered = nbt.getBoolean("redstonePowered");
|
||||||
|
|
||||||
coreState.pipeId = nbt.getInteger("pipeId");
|
coreState.pipeId = nbt.getInteger("pipeId");
|
||||||
pipe = BlockGenericPipe.createPipe(coreState.pipeId);
|
pipe = BlockGenericPipe.createPipe(coreState.pipeId);
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,9 @@ public class PipeItemsGold extends Pipe {
|
||||||
return PipeIconProvider.TYPE.PipeItemsGold.ordinal();
|
return PipeIconProvider.TYPE.PipeItemsGold.ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleEvent(PipeEventItem.AdjustSpeed event) {
|
public void eventHandler(PipeEventItem.AdjustSpeed event) {
|
||||||
event.handled = true;
|
event.handled = true;
|
||||||
TravelingItem item = event.item;
|
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();
|
return PipeIconProvider.TYPE.PipeItemsVoid.ordinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleEvent(PipeEventItem.DropItem event) {
|
public void eventHandler(PipeEventItem.DropItem event) {
|
||||||
event.entity = null;
|
event.entity = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleEvent(PipeEventItem.ReachedCenter event) {
|
public void eventHandler(PipeEventItem.ReachedCenter event) {
|
||||||
transport.items.scheduleRemoval(event.item);
|
transport.items.scheduleRemoval(event.item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class TriggerRedstoneInput extends BCTrigger implements ITriggerPipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBeingPowered(Pipe pipe) {
|
private boolean isBeingPowered(Pipe pipe) {
|
||||||
return pipe.container.worldObj.isBlockIndirectlyGettingPowered(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
|
return pipe.container.redstonePowered;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue