bocci the cock

This commit is contained in:
Boblet 2025-04-08 16:37:39 +02:00
parent 4c501d209f
commit 1282e525da
6 changed files with 174 additions and 31 deletions

View File

@ -1,7 +1,6 @@
package com.hbm.inventory.container;
import com.hbm.inventory.SlotPattern;
import com.hbm.inventory.SlotUpgrade;
import com.hbm.tileentity.network.TileEntityPneumoTube;
import net.minecraft.entity.player.EntityPlayer;
@ -23,10 +22,6 @@ public class ContainerPneumoTube extends ContainerBase {
}
}
//upgrades
this.addSlotToContainer(new SlotUpgrade(tube, 15, 152, 23));
this.addSlotToContainer(new SlotUpgrade(tube, 16, 152, 47));
playerInv(invPlayer, 8, 103, 161);
}

View File

@ -58,24 +58,18 @@ public class GUIPneumoTube extends GuiInfoContainer {
protected void mouseClicked(int x, int y, int i) {
super.mouseClicked(x, y, i);
if(checkClick(x, y, 7, 52, 18, 18)) {
click(x, y, 7, 52, 18, 18, "redstone");
click(x, y, 6, 36, 20, 8, "pressure");
click(x, y, 128, 30, 14, 26, "whitelist");
click(x, y, 151, 16, 18, 18, "receive");
click(x, y, 151, 52, 18, 18, "send");
}
public void click(int x, int y, int left, int top, int sizeX, int sizeY, String name) {
if(checkClick(x, y, left, top, sizeX, sizeY)) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
NBTTagCompound data = new NBTTagCompound();
data.setBoolean("redstone", true);
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, tube.xCoord, tube.yCoord, tube.zCoord));
}
if(checkClick(x, y, 6, 36, 20, 8)) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
NBTTagCompound data = new NBTTagCompound();
data.setBoolean("pressure", true);
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, tube.xCoord, tube.yCoord, tube.zCoord));
}
if(checkClick(x, y, 128, 30, 14, 26)) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
NBTTagCompound data = new NBTTagCompound();
data.setBoolean("whitelist", true);
data.setBoolean(name, true);
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, tube.xCoord, tube.yCoord, tube.zCoord));
}
}
@ -101,6 +95,9 @@ public class GUIPneumoTube extends GuiInfoContainer {
} else {
drawTexturedModalRect(guiLeft + 139, guiTop + 47, 176, 0, 3, 6);
}
drawTexturedModalRect(guiLeft + 151, guiTop + 16, 197, 18 * tube.receiveOrder, 18, 18);
drawTexturedModalRect(guiLeft + 151, guiTop + 52, 215, 18 * tube.sendOrder, 18, 18);
drawTexturedModalRect(guiLeft + 6 + 4 * (tube.compair.getPressure() - 1), guiTop + 36, 179, 18, 4, 8);
GaugeUtil.drawSmoothGauge(guiLeft + 16, guiTop + 25, this.zLevel, (double) tube.compair.getFill() / (double) tube.compair.getMaxFill(), 5, 2, 1, 0xCA6C43, 0xAB4223);

View File

@ -12,6 +12,7 @@ import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.uninos.GenNode;
import com.hbm.uninos.UniNodespace;
import com.hbm.uninos.networkproviders.PneumaticNetwork;
import com.hbm.uninos.networkproviders.PneumaticNetworkProvider;
import com.hbm.util.Compat;
import com.hbm.util.EnumUtil;
@ -43,13 +44,16 @@ public class TileEntityPneumoTube extends TileEntityMachineBase implements IGUIP
public boolean whitelist = false;
public boolean redstone = false;
public byte sendOrder = 0;
public byte receiveOrder = 0;
public boolean didSend = false;
public FluidTank compair;
protected PneumaticNode node;
public TileEntityPneumoTube() {
super(17);
super(15);
this.compair = new FluidTank(Fluids.AIR, 4_000).withPressure(1);
}
@ -80,26 +84,46 @@ public class TileEntityPneumoTube extends TileEntityMachineBase implements IGUIP
}
if(this.isCompressor()) {
int randTime = Math.abs((int) (worldObj.getTotalWorldTime() + this.getIdentifier(xCoord, yCoord, zCoord)));
if(worldObj.getTotalWorldTime() % 10 == 0) for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if(dir != this.insertionDir && dir != this.ejectionDir) {
this.trySubscribe(compair.getTankType(), worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
}
}
if(worldObj.getTotalWorldTime() % 40 == 0 && this.compair.getFill() > 0) {
//this.compair.setFill(0);
//worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:weapon.reload.tubeFwoomp", 1.0F, 1.0F);
if(randTime % 40 == 0 && didSend) {
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "hbm:weapon.reload.tubeFwoomp", 0.5F, 0.9F + worldObj.rand.nextFloat() * 0.2F);
}
if(randTime % 5 == 0 && this.node != null && !this.node.expired && this.node.net != null && this.compair.getFill() >= 50) {
TileEntity sendFrom = Compat.getTileStandard(worldObj, xCoord + insertionDir.offsetX, yCoord + insertionDir.offsetY, zCoord + insertionDir.offsetZ);
if(sendFrom instanceof IInventory) {
PneumaticNetwork net = node.net;
if(net.send((IInventory) sendFrom, this, this.insertionDir.getOpposite(), sendOrder, receiveOrder)) {
this.didSend = true;
this.compair.setFill(this.compair.getFill() - 50);
}
}
}
}
if(this.isEndpoint() && this.node != null && this.node.net != null && worldObj.getTotalWorldTime() % 10 == 0) {
TileEntity tile = Compat.getTileStandard(worldObj, xCoord + this.ejectionDir.offsetX, yCoord + this.ejectionDir.offsetY, zCoord + this.ejectionDir.offsetZ);
if(tile instanceof IInventory) this.node.net.addReceiver((IInventory) tile);
if(tile instanceof IInventory) this.node.net.addReceiver((IInventory) tile, this.ejectionDir);
}
this.networkPackNT(15);
}
}
// tactfully copy pasted from BlockPos
public static int getIdentifier(int x, int y, int z) {
return (y + z * 27644437) * 27644437 + x;
}
@Override
public long getReceiverSpeed(FluidType type, int pressure) {
@ -130,6 +154,8 @@ public class TileEntityPneumoTube extends TileEntityMachineBase implements IGUIP
super.serialize(buf);
buf.writeBoolean(redstone);
buf.writeBoolean(whitelist);
buf.writeByte(sendOrder);
buf.writeByte(receiveOrder);
pattern.serialize(buf);
compair.serialize(buf);
}
@ -139,6 +165,8 @@ public class TileEntityPneumoTube extends TileEntityMachineBase implements IGUIP
super.deserialize(buf);
this.redstone = buf.readBoolean();
this.whitelist = buf.readBoolean();
this.sendOrder = buf.readByte();
this.receiveOrder = buf.readByte();
pattern.deserialize(buf);
compair.deserialize(buf);
}
@ -215,6 +243,14 @@ public class TileEntityPneumoTube extends TileEntityMachineBase implements IGUIP
if(pressure > 5) pressure = 1;
this.compair.withPressure(pressure);
}
if(data.hasKey("send")) {
this.sendOrder++;
if(this.sendOrder > 2) this.sendOrder = 0;
}
if(data.hasKey("receive")) {
this.receiveOrder++;
if(this.receiveOrder > 1) this.receiveOrder = 0;
}
this.markDirty();
}
@ -225,7 +261,7 @@ public class TileEntityPneumoTube extends TileEntityMachineBase implements IGUIP
@Override public FluidTank[] getAllTanks() { return new FluidTank[] {compair}; }
@Override public FluidTank[] getReceivingTanks() { return new FluidTank[] {compair}; }
public static class PneumaticNode extends GenNode {
public static class PneumaticNode extends GenNode<PneumaticNetwork> {
public PneumaticNode(BlockPos... positions) {
super(PneumaticNetworkProvider.THE_PROVIDER, positions);

View File

@ -1,11 +1,107 @@
package com.hbm.uninos.networkproviders;
import com.hbm.tileentity.network.TileEntityPneumoTube.PneumaticNode;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import com.hbm.tileentity.network.TileEntityPneumoTube;
import com.hbm.uninos.NodeNet;
import com.hbm.util.BobMathUtil;
import com.hbm.util.Tuple.Pair;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class PneumaticNetwork extends NodeNet<IInventory, IInventory, PneumaticNode> {
public class PneumaticNetwork extends NodeNet {
@Override public void update() { }
public static final byte SEND_FIRST = 0;
public static final byte SEND_LAST = 1;
public static final byte SEND_RANDOM = 2;
public static final byte RECEIVE_ROBIN = 0;
public static final byte RECEIVE_RANDOM = 1;
public int nextReceiver = 0;
protected static int timeout = 1_000;
public HashMap<IInventory, Pair<ForgeDirection, Long>> receivers = new HashMap();
public void addReceiver(IInventory inventory, ForgeDirection pipeDir) {
receivers.put(inventory, new Pair(pipeDir, System.currentTimeMillis()));
}
@Override public void update() {
long timestamp = System.currentTimeMillis();
receivers.entrySet().removeIf(x -> { return (timestamp - x.getValue().getValue() > timeout) || NodeNet.isBadLink(x.getKey()); });
}
public boolean send(IInventory source, TileEntityPneumoTube tube, ForgeDirection dir, int sendOrder, int receiveOrder) {
if(receivers.isEmpty()) return false;
int[] slotAccess;
if(source instanceof ISidedInventory) {
ISidedInventory sided = (ISidedInventory) source;
slotAccess = sided.getAccessibleSlotsFromSide(dir.ordinal());
} else {
slotAccess = new int[source.getSizeInventory()];
for(int i = 0; i < source.getSizeInventory(); i++) slotAccess[i] = i;
}
if(sendOrder == SEND_LAST) BobMathUtil.reverseIntArray(slotAccess);
if(sendOrder == SEND_RANDOM) BobMathUtil.shuffleIntArray(slotAccess);
nextReceiver++;
ReceiverComparator comparator = new ReceiverComparator(tube);
List<Entry<IInventory, Pair<ForgeDirection, Long>>> receiverList = new ArrayList(receivers.size());
receiverList.addAll(receivers.entrySet());
receiverList.sort(comparator);
int index = nextReceiver % receivers.size();
Entry<IInventory, Pair<ForgeDirection, Long>> chosenReceiverEntry = receiverList.get(index);
//TBI - the painful part
return false;
}
public static class ReceiverComparator implements Comparator<Entry<IInventory, Pair<ForgeDirection, Long>>> {
private TileEntityPneumoTube origin;
public ReceiverComparator(TileEntityPneumoTube origin) {
this.origin = origin;
}
@Override
public int compare(Entry<IInventory, Pair<ForgeDirection, Long>> o1, Entry<IInventory, Pair<ForgeDirection, Long>> o2) {
TileEntity tile1 = o1.getKey() instanceof TileEntity ? (TileEntity) o1.getKey() : null;
TileEntity tile2 = o2.getKey() instanceof TileEntity ? (TileEntity) o2.getKey() : null;
//prioritize actual TileEntities
if(tile1 == null && tile2 != null) return 1;
if(tile1 != null && tile2 == null) return -1;
if(tile1 == null && tile2 == null) return 0;
//calculate distances from origin
int dist1 = (tile1.xCoord - origin.xCoord) * (tile1.xCoord - origin.xCoord) + (tile1.yCoord - origin.yCoord) * (tile1.yCoord - origin.yCoord) + (tile1.zCoord - origin.zCoord) * (tile1.zCoord - origin.zCoord);
int dist2 = (tile2.xCoord - origin.xCoord) * (tile2.xCoord - origin.xCoord) + (tile2.yCoord - origin.yCoord) * (tile2.yCoord - origin.yCoord) + (tile2.zCoord - origin.zCoord) * (tile2.zCoord - origin.zCoord);
//tier-breaker: use hash value instead
if(dist1 == dist2) {
return TileEntityPneumoTube.getIdentifier(tile1.xCoord, tile1.yCoord, tile1.zCoord) - TileEntityPneumoTube.getIdentifier(tile2.xCoord, tile2.yCoord, tile2.zCoord);
}
//no tie? return difference of the distances
return dist1 - dist2;
}
}
}

View File

@ -260,7 +260,26 @@ public class BobMathUtil {
public static int[] collectionToIntArray(Collection<? extends Object> in, ToIntFunction<? super Object> mapper) {
return Arrays.stream(in.toArray()).mapToInt(mapper).toArray();
}
}
public static void shuffleIntArray(int[] array) {
Random rand = new Random();
for(int i = array.length - 1; i > 0; i--) {
int r = rand.nextInt(i + 1);
int temp = array[r];
array[r] = array[i];
array[i] = temp;
}
}
public static void reverseIntArray(int[] array) {
int len = array.length;
for(int i = 0; i < len / 2; i++) {
int temp = array[i];
array[i] = array[len - 1 - i];
array[len - 1 - i] = temp;
}
}
/** Soft peak sine */
public static double sps(double x) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB