mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-26 23:02:59 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77c4dee42f | ||
|
|
06e0821e67 | ||
|
|
a950c8f23b |
No files matched your search
@@ -3,9 +3,9 @@ name: Build and test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ master, main ]
|
||||
branches: [ master, main, release/** ]
|
||||
push:
|
||||
branches: [ master, main ]
|
||||
branches: [ master, main, release/** ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
|
||||
@@ -91,16 +91,11 @@ public class ItemCertusQuartzTank extends BaseItemBlockContainer implements IFlu
|
||||
|
||||
if (!container.stackTagCompound.hasKey("tileEntity")
|
||||
|| container.stackTagCompound.getCompoundTag("tileEntity").hasKey("Empty")) {
|
||||
NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());
|
||||
|
||||
if (this.capacity < resource.amount) {
|
||||
fluidTag.setInteger("Amount", this.capacity);
|
||||
container.stackTagCompound.setTag("tileEntity", fluidTag);
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
int finalAmount = Math.min(resource.amount, this.capacity);
|
||||
NBTTagCompound fluidTag = new FluidStack(resource.getFluid(), finalAmount, resource.tag)
|
||||
.writeToNBT(new NBTTagCompound());
|
||||
container.stackTagCompound.setTag("tileEntity", fluidTag);
|
||||
return resource.amount;
|
||||
return finalAmount;
|
||||
}
|
||||
|
||||
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("tileEntity");
|
||||
|
||||
@@ -11,7 +11,7 @@ import appeng.tile.inventory.InvOperation;
|
||||
|
||||
public class TileOCPatternEditor extends AEBaseInvTile {
|
||||
|
||||
private final AppEngInternalInventory invItems = new AppEngInternalInventory(this, 16, 1);
|
||||
private final AppEngInternalInventory invItems = new AppEngInternalInventory(this, 16);
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory() {
|
||||
|
||||
+144
-51
@@ -3,24 +3,31 @@ package com.glodblock.github.crossmod.opencomputers;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import com.glodblock.github.common.item.ItemFluidDrop;
|
||||
import com.glodblock.github.common.item.ItemFluidEncodedPattern;
|
||||
import com.glodblock.github.common.tile.TileOCPatternEditor;
|
||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import com.glodblock.github.util.Util;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.items.misc.ItemEncodedPattern;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import li.cil.oc.api.driver.EnvironmentProvider;
|
||||
import li.cil.oc.api.driver.NamedBlock;
|
||||
import li.cil.oc.api.internal.Database;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import li.cil.oc.api.network.Component;
|
||||
import li.cil.oc.api.network.ManagedEnvironment;
|
||||
import li.cil.oc.api.network.Node;
|
||||
import li.cil.oc.api.prefab.DriverSidedTileEntity;
|
||||
import li.cil.oc.integration.ManagedTileEntityEnvironment;
|
||||
import li.cil.oc.integration.appeng.internal.PatternEnvironment;
|
||||
import li.cil.oc.integration.appeng.internal.PatternEnvironment$class;
|
||||
|
||||
public class DriverOCPatternEditor extends DriverSidedTileEntity {
|
||||
|
||||
@@ -36,33 +43,12 @@ public class DriverOCPatternEditor extends DriverSidedTileEntity {
|
||||
return new DriverOCPatternEditor.Environment((TileOCPatternEditor) world.getTileEntity(x, y, z));
|
||||
}
|
||||
|
||||
public static class Environment extends ManagedTileEntityEnvironment<TileOCPatternEditor>
|
||||
implements NamedBlock, PatternEnvironment {
|
||||
public static class Environment extends ManagedTileEntityEnvironment<TileOCPatternEditor> implements NamedBlock {
|
||||
|
||||
public Environment(TileOCPatternEditor tileEntity) {
|
||||
super(tileEntity, NameConst.BLOCK_OC_PATTERN_EDITOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getPatternInventory(Context context, Arguments args) {
|
||||
return tileEntity.getInternalInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int offset() {
|
||||
return PatternEnvironment$class.offset(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] setPatternSlot(Context context, Arguments args, String tag) {
|
||||
return PatternEnvironment$class.setPatternSlot(this, context, args, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] storeInterfacePattern(Context context, Arguments args, String tag) {
|
||||
return PatternEnvironment$class.storeInterfacePattern(this, context, args, tag);
|
||||
}
|
||||
|
||||
private int optSlot(Arguments args, IInventory inv, int index, int def) {
|
||||
if (index >= 0 && index < args.count()) {
|
||||
int slot = args.checkInteger(index) - 1;
|
||||
@@ -76,21 +62,130 @@ public class DriverOCPatternEditor extends DriverSidedTileEntity {
|
||||
}
|
||||
|
||||
private int checkSlot(Arguments args, IInventory inv, int index) {
|
||||
int slot = args.checkInteger(index) - 1;
|
||||
if (slot < 0 || slot >= inv.getSizeInventory()) {
|
||||
if (index >= 0 && index < args.count()) {
|
||||
int slot = args.checkInteger(index) - 1;
|
||||
if (slot < 0 || slot >= inv.getSizeInventory()) {
|
||||
throw new IllegalArgumentException("invalid slot");
|
||||
}
|
||||
return slot;
|
||||
} else {
|
||||
throw new IllegalArgumentException("invalid slot");
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
|
||||
private void replaceBlankPattern(Arguments args) {
|
||||
IInventory inv = tileEntity.getInternalInventory();
|
||||
int slot = checkSlot(args, inv, 0);
|
||||
if (AEApi.instance().definitions().materials().blankPattern().isSameAs(inv.getStackInSlot(slot))) {
|
||||
ItemStack pattern = AEApi.instance().definitions().items().encodedUltimatePattern().maybeStack(1).get();
|
||||
pattern.setTagCompound(new NBTTagCompound());
|
||||
inv.setInventorySlotContents(slot, pattern);
|
||||
private boolean validPattern(ItemStack pattern) {
|
||||
if (pattern == null) {
|
||||
throw new IllegalArgumentException("No pattern here!");
|
||||
}
|
||||
if (pattern.getItem() instanceof ItemEncodedPattern iep
|
||||
&& !(pattern.getItem() instanceof ItemFluidEncodedPattern)) {
|
||||
return iep.getOutput(pattern) == null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private ItemStack getStack(Arguments args) {
|
||||
if (args.count() > 1) {
|
||||
String address;
|
||||
int entry;
|
||||
int size;
|
||||
if (args.isString(0)) {
|
||||
address = args.checkString(0);
|
||||
entry = args.checkInteger(1);
|
||||
size = args.optInteger(2, 1);
|
||||
} else {
|
||||
address = args.checkString(1);
|
||||
entry = args.checkInteger(2);
|
||||
size = args.optInteger(3, 1);
|
||||
}
|
||||
Node node = node().network().node(address);
|
||||
if (node instanceof Component) {
|
||||
if (node.host() instanceof Database) {
|
||||
ItemStack dbStack = ((Database) node.host()).getStackInSlot(entry - 1);
|
||||
if (dbStack == null || size < 1) {
|
||||
return null;
|
||||
} else {
|
||||
dbStack.stackSize = Math.min(size, dbStack.getMaxStackSize());
|
||||
return dbStack;
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("not a database");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("no such component");
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] clearInterfacePattern(Context context, Arguments args, String tag) {
|
||||
IInventory inv = tileEntity.getInternalInventory();
|
||||
ItemStack pattern = inv.getStackInSlot(checkSlot(args, inv, 0));
|
||||
if (validPattern(pattern)) {
|
||||
NBTTagCompound encodedValue = pattern.getTagCompound();
|
||||
int slot = checkSlot(args, inv, 0);
|
||||
if (encodedValue == null) throw new IllegalArgumentException("No pattern here!");
|
||||
NBTTagList nbt = encodedValue.getTagList(tag, 10);
|
||||
int index = args.checkInteger(1) - 1;
|
||||
if (index < 0) throw new IllegalArgumentException("Invalid index!");
|
||||
nbt.removeTag(index);
|
||||
encodedValue.setTag(tag, nbt);
|
||||
pattern.setTagCompound(encodedValue);
|
||||
inv.setInventorySlotContents(slot, null);
|
||||
inv.setInventorySlotContents(slot, pattern);
|
||||
context.pause(0.1);
|
||||
return new Object[] { true };
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not Fluid Encoded pattern!");
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] setPatternSlot(Context context, Arguments args, String tag, boolean fluid) {
|
||||
IInventory inv = tileEntity.getInternalInventory();
|
||||
int slot = args.isString(0) ? 0 : optSlot(args, inv, 0, 0);
|
||||
ItemStack stack = getStack(args);
|
||||
if (fluid) {
|
||||
FluidStack fluids = Util.getFluidFromItem(stack);
|
||||
stack = ItemFluidDrop.newStack(fluids);
|
||||
}
|
||||
int index = args.checkInteger(4) - 1;
|
||||
if (index < 0 || index > 511) throw new IllegalArgumentException("Invalid index!");
|
||||
ItemStack pattern = inv.getStackInSlot(slot);
|
||||
if (validPattern(pattern)) {
|
||||
NBTTagCompound encodedValue = pattern.getTagCompound();
|
||||
if (encodedValue == null) throw new IllegalArgumentException("No pattern here!");
|
||||
|
||||
NBTTagList inTag = encodedValue.getTagList(tag, 10);
|
||||
while (inTag.tagCount() <= index) inTag.appendTag(new NBTTagCompound());
|
||||
if (stack != null) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
AEItemStack aeStack = AEItemStack.create(stack);
|
||||
aeStack.writeToNBT(nbt);
|
||||
inTag.func_150304_a(index, nbt);
|
||||
} else {
|
||||
inTag.removeTag(index);
|
||||
}
|
||||
encodedValue.setTag(tag, inTag);
|
||||
pattern.setTagCompound(encodedValue);
|
||||
inv.setInventorySlotContents(slot, null);
|
||||
inv.setInventorySlotContents(slot, pattern);
|
||||
context.pause(0.1);
|
||||
return new Object[] { true };
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not Fluid Encoded pattern!");
|
||||
}
|
||||
}
|
||||
|
||||
@Callback(doc = "function([slot:number]):table -- Get the configuration of the interface.")
|
||||
public Object[] getInterfaceConfiguration(Context context, Arguments args) {
|
||||
IInventory config = tileEntity.getInternalInventory();
|
||||
int slot = optSlot(args, config, 0, 0);
|
||||
ItemStack stack = config.getStackInSlot(slot);
|
||||
if (!validPattern(stack)) {
|
||||
throw new IllegalArgumentException("Not Fluid Encoded pattern!");
|
||||
}
|
||||
return new Object[] { stack };
|
||||
}
|
||||
|
||||
@Callback(doc = "function([slot:number]):table -- Get the given pattern in the interface.")
|
||||
@@ -102,39 +197,37 @@ public class DriverOCPatternEditor extends DriverSidedTileEntity {
|
||||
}
|
||||
|
||||
@Callback(
|
||||
doc = "function(slot:number, index:number[, database:address, entry:number, size:number]):boolean OR function(slot:number, index:number[, detail:table, type:string]):boolean -- Set the pattern input at the given index. A blank pattern becomes an ultimate pattern.")
|
||||
public Object[] setInterfacePatternInput(Context context, Arguments args) {
|
||||
replaceBlankPattern(args);
|
||||
return setPatternSlot(context, args, "in");
|
||||
doc = "function(slot:number, database:address, entry:number, size:number, index:number):boolean -- Set the pattern item input at the given index.")
|
||||
public Object[] setInterfacePatternItemInput(Context context, Arguments args) {
|
||||
return setPatternSlot(context, args, "in", false);
|
||||
}
|
||||
|
||||
@Callback(
|
||||
doc = "function(slot:number, index:number[, database:address, entry:number, size:number]):boolean OR function(slot:number, index:number[, detail:table, type:string]):boolean -- Set the pattern output at the given index. A blank pattern becomes an ultimate pattern.")
|
||||
public Object[] setInterfacePatternOutput(Context context, Arguments args) {
|
||||
replaceBlankPattern(args);
|
||||
return setPatternSlot(context, args, "out");
|
||||
doc = "function(slot:number, database:address, entry:number, size:number, index:number):boolean -- Set the pattern item output at the given index.")
|
||||
public Object[] setInterfacePatternItemOutput(Context context, Arguments args) {
|
||||
return setPatternSlot(context, args, "out", false);
|
||||
}
|
||||
|
||||
@Callback(
|
||||
doc = "function(slot:number, index:number, database:address, entry:number):boolean -- Store pattern input at the given index to the database entry.")
|
||||
public Object[] storeInterfacePatternInput(Context context, Arguments args) {
|
||||
return storeInterfacePattern(context, args, "in");
|
||||
doc = "function(slot:number, database:address, entry:number, size:number, index:number):boolean -- Set the pattern fluid input at the given index.")
|
||||
public Object[] setInterfacePatternFluidInput(Context context, Arguments args) {
|
||||
return setPatternSlot(context, args, "in", true);
|
||||
}
|
||||
|
||||
@Callback(
|
||||
doc = "function(slot:number, index:number, database:address, entry:number):boolean -- Store pattern output at the given index to the database entry.")
|
||||
public Object[] storeInterfacePatternOutput(Context context, Arguments args) {
|
||||
return storeInterfacePattern(context, args, "out");
|
||||
doc = "function(slot:number, database:address, entry:number, size:number, index:number):boolean -- Set the pattern fluid output at the given index.")
|
||||
public Object[] setInterfacePatternFluidOutput(Context context, Arguments args) {
|
||||
return setPatternSlot(context, args, "out", true);
|
||||
}
|
||||
|
||||
@Callback(doc = "function(slot:number, index:number):boolean -- Clear pattern input at the given index.")
|
||||
public Object[] clearInterfacePatternInput(Context context, Arguments args) {
|
||||
return setPatternSlot(context, args, "in");
|
||||
return clearInterfacePattern(context, args, "in");
|
||||
}
|
||||
|
||||
@Callback(doc = "function(slot:number, index:number):boolean -- Clear pattern output at the given index.")
|
||||
public Object[] clearInterfacePatternOutput(Context context, Arguments args) {
|
||||
return setPatternSlot(context, args, "out");
|
||||
return clearInterfacePattern(context, args, "out");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -59,8 +59,9 @@ public class WirelessMagnet {
|
||||
// This method uses the same algorithm as the magnet from draconic evolution
|
||||
// if changes are ever made, they should be made on both
|
||||
public static void doMagnet(ItemStack wirelessTerm, EntityPlayer player) {
|
||||
if (player.ticksExisted % 5 != 0 || player.isSneaking() || !isConfigured(wirelessTerm)) return;
|
||||
World world = player.worldObj;
|
||||
final World world = player.worldObj;
|
||||
if (world.isRemote || player.ticksExisted % 5 != 0 || player.isSneaking() || !isConfigured(wirelessTerm))
|
||||
return;
|
||||
final List<EntityItem> items = getEntitiesInRange(
|
||||
EntityItem.class,
|
||||
world,
|
||||
@@ -70,9 +71,7 @@ public class WirelessMagnet {
|
||||
magnetRange);
|
||||
final boolean skipPlayerCheck = world.playerEntities.size() < 2;
|
||||
boolean playSound = false;
|
||||
// account for the server/client desync
|
||||
double playerEyesPos = player.posY
|
||||
+ (world.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight());
|
||||
double playerEyesPos = player.posY + player.getEyeHeight();
|
||||
|
||||
for (EntityItem itemToGet : items) {
|
||||
if (itemToGet.getEntityItem() == null || itemToGet instanceof EntityFloatingItem) {
|
||||
@@ -95,6 +94,10 @@ public class WirelessMagnet {
|
||||
player.posX - 0.2 + (world.rand.nextDouble() * 0.4),
|
||||
playerEyesPos - 0.62,
|
||||
player.posZ - 0.2 + (world.rand.nextDouble() * 0.4));
|
||||
// EntityTracker only syncs item positions every 20 ticks and skips small velocity changes,
|
||||
// so force both; otherwise the client keeps simulating the item with its old motion.
|
||||
itemToGet.isAirBorne = true; // force position update
|
||||
itemToGet.velocityChanged = true; // force velocity update
|
||||
}
|
||||
|
||||
if (playSound) {
|
||||
@@ -105,33 +108,31 @@ public class WirelessMagnet {
|
||||
0.5F * ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 2F));
|
||||
}
|
||||
|
||||
if (!world.isRemote) {
|
||||
// xp
|
||||
final List<EntityXPOrb> xpOrbs = getEntitiesInRange(
|
||||
EntityXPOrb.class,
|
||||
world,
|
||||
(int) player.posX,
|
||||
(int) player.posY,
|
||||
(int) player.posZ,
|
||||
magnetRange);
|
||||
// xp
|
||||
final List<EntityXPOrb> xpOrbs = getEntitiesInRange(
|
||||
EntityXPOrb.class,
|
||||
world,
|
||||
(int) player.posX,
|
||||
(int) player.posY,
|
||||
(int) player.posZ,
|
||||
magnetRange);
|
||||
|
||||
for (EntityXPOrb xpToGet : xpOrbs) {
|
||||
if (xpToGet.field_70532_c == 0 && xpToGet.isEntityAlive()) {
|
||||
if (!skipPlayerCheck) {
|
||||
EntityPlayer closestPlayer = world.getClosestPlayerToEntity(xpToGet, magnetRange);
|
||||
if (closestPlayer == null || closestPlayer != player) continue;
|
||||
}
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(new PlayerPickupXpEvent(player, xpToGet))) continue;
|
||||
world.playSoundAtEntity(
|
||||
player,
|
||||
"random.orb",
|
||||
0.1F,
|
||||
0.5F * ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.8F));
|
||||
player.onItemPickup(xpToGet, 1);
|
||||
player.addExperience(xpToGet.xpValue);
|
||||
xpToGet.setDead();
|
||||
for (EntityXPOrb xpToGet : xpOrbs) {
|
||||
if (xpToGet.field_70532_c == 0 && xpToGet.isEntityAlive()) {
|
||||
if (!skipPlayerCheck) {
|
||||
EntityPlayer closestPlayer = world.getClosestPlayerToEntity(xpToGet, magnetRange);
|
||||
if (closestPlayer == null || closestPlayer != player) continue;
|
||||
}
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(new PlayerPickupXpEvent(player, xpToGet))) continue;
|
||||
world.playSoundAtEntity(
|
||||
player,
|
||||
"random.orb",
|
||||
0.1F,
|
||||
0.5F * ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.8F));
|
||||
player.onItemPickup(xpToGet, 1);
|
||||
player.addExperience(xpToGet.xpValue);
|
||||
xpToGet.setDead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user