Compare commits

...
Author SHA1 Message Date
Martin Robertz 5b48491b4d Merge remote-tracking branch 'origin/magnet' into dev 2025-06-09 15:36:53 +02:00
Martin Robertz dd5ae74dd9 Merge remote-tracking branch 'Kogepan229/rewrite-level-maintainer' into dev 2025-06-09 15:36:49 +02:00
Martin Robertz 5d6fced15c Merge branch 'master' into dev
# Conflicts:
#	dependencies.gradle
2025-06-09 15:36:40 +02:00
Martin Robertz 1ffcea9dd9 update 2025-06-09 15:35:46 +02:00
Martin Robertz 50bcccb3e5 Merge remote-tracking branch 'lordIcocain/super_stoker' into dev 2025-06-09 15:35:03 +02:00
RecursivePineapple 3428c86f64 Fix div by zero (#306) 2025-06-09 12:25:06 +02:00
Kogepan229 ec10dbebab Merge branch 'master' into rewrite-level-maintainer 2025-06-09 10:23:06 +09:00
Alexdoru e6b9d1a6c2 add comment 2025-06-08 21:54:08 +02:00
Alexdoru 3495179f0e account for client /server desync when teleporting items with magnet 2025-06-08 21:33:12 +02:00
Alexdoru c504dbb28a Magnet improvements (#303) 2025-06-08 19:42:19 +02:00
lordIcocain 708fe0e731 new texture 2025-06-08 13:07:50 +03:00
Martin Robertz 2ce439c997 update 2025-06-08 12:07:25 +02:00
Martin Robertz 9f2d51cdcf Merge remote-tracking branch 'lordIcocain/universal_terminal_universal_bauble' into dev 2025-06-08 12:06:06 +02:00
Martin Robertz 7f5954847f Merge remote-tracking branch 'lordIcocain/ae-navite-fluid-support' into dev 2025-06-08 12:06:02 +02:00
lordIcocain 6d43b9aee7 make universal terminal universal bauble 2025-06-08 12:17:59 +03:00
lordIcocain e8f25f8487 fix patterning without inputs/outputs 2025-06-06 21:13:39 +03:00
Martin Robertz 0d7425cb82 update 2025-06-05 21:51:23 +02:00
Martin Robertz 47a1d87522 Merge remote-tracking branch 'origin/magnet' into dev 2025-06-05 21:51:01 +02:00
Alexdoru 01865afd10 don't magnet fake entity items from ME assemblers 2025-06-04 17:43:52 +02:00
Alexdoru d5cb385fc1 remove check who dropped the item 2025-06-04 17:42:04 +02:00
Alexdoru 08bffd9d50 cache Enum.values() call for WirelessMagnet.Mode enum 2025-06-04 17:23:47 +02:00
Alexdoru 1591a73c38 teleport items on the clientside as well 2025-06-04 17:16:08 +02:00
Alexdoru dd0554ce64 play a sound when picking up items 2025-06-04 17:13:21 +02:00
Alexdoru 8aa0eddb24 fire the PlayerPickupXpEvent 2025-06-04 17:09:57 +02:00
Alexdoru 42616147aa change while loops to for loops and correct the generic method signature 2025-06-04 17:05:19 +02:00
Alexdoru cc3ed57790 delete NBTTagCompound hallucination 2025-06-04 17:01:15 +02:00
Alexdoru 25ee628e7f only run magnet logic every 5 ticks 2025-06-04 17:01:15 +02:00
Alexdoru ab816d2ebe avoid checking for other players for every item if alone 2025-06-04 17:01:15 +02:00
7 changed files with 109 additions and 91 deletions

No files matched your search

+5 -5
View File
@@ -34,11 +34,11 @@
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
api('com.github.GTNewHorizons:NotEnoughItems:2.7.51-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-630-GTNH-pre:dev')
api('com.github.GTNewHorizons:NotEnoughItems:2.7.52-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-634-GTNH-pre:dev')
api('curse.maven:cofh-core-69162:2388751')
api('com.github.GTNewHorizons:waila:1.8.7:dev')
api("com.github.GTNewHorizons:GTNHLib:0.6.27:dev")
api("com.github.GTNewHorizons:GTNHLib:0.6.30:dev")
implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.12.3:dev") {
exclude group: 'com.github.GTNewHorizons', module: 'Applied-Energistics-2-Unofficial'
@@ -48,7 +48,7 @@ dependencies {
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.35:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ForestryMC:4.10.11:dev')
compileOnly('com.github.GTNewHorizons:EnderIO:2.9.16:dev')
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.51.332:dev') {
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.51.339:dev') {
exclude group: 'com.github.GTNewHorizons', module: 'AE2FluidCraft-Rework'
exclude group: 'com.github.GTNewHorizons', module: 'Applied-Energistics-2-Unofficial'
}
@@ -57,7 +57,7 @@ dependencies {
compileOnly('com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:OpenComputers:1.11.16-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.7.7-GTNH:dev') { transitive = false }
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.6.72:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.6.76:dev") { transitive = false }
runtimeOnlyNonPublishable("com.github.GTNewHorizons:DuraDisplay:1.3.4:dev")
}
@@ -395,25 +395,27 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
}
public void encode() {
fillPattern();
if (isCraftingMode()) {
encodeItemPattern();
return;
}
ItemStack stack = this.patternSlotOUT.getStack();
if (stack == null) {
stack = this.patternSlotIN.getStack();
if (notPattern(stack)) {
if (getInputs() != null && getOutputs() != null) {
fillPattern();
if (isCraftingMode()) {
encodeItemPattern();
return;
}
if (stack.stackSize == 1) {
this.patternSlotIN.putStack(null);
} else {
stack.stackSize--;
ItemStack stack = this.patternSlotOUT.getStack();
if (stack == null) {
stack = this.patternSlotIN.getStack();
if (notPattern(stack)) {
return;
}
if (stack.stackSize == 1) {
this.patternSlotIN.putStack(null);
} else {
stack.stackSize--;
}
encodeFluidPattern();
} else if (!notPattern(stack)) {
encodeFluidPattern();
}
encodeFluidPattern();
} else if (!notPattern(stack)) {
encodeFluidPattern();
}
}
@@ -422,10 +424,6 @@ public abstract class FCContainerEncodeTerminal extends ContainerItemMonitor
final ItemStack[] in = this.getInputs();
final ItemStack[] out = this.getOutputs();
// if there is no input, this would be silly.
if (in == null || out == null) {
return;
}
// first check the output slots, should either be null, or a pattern
if (output != null && this.notPattern(output)) {
return;
@@ -230,7 +230,7 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
@Override
public BaubleType getBaubleType(ItemStack itemStack) {
return BaubleType.RING;
return BaubleType.UNIVERSAL;
}
@Override
@@ -274,9 +274,9 @@ public class ItemWirelessUltraTerminal extends ItemBaseWirelessTerminal
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int slot, boolean p_77663_5_) {
if (Platform.isServer() && entityIn instanceof EntityPlayer player) {
if (entityIn instanceof EntityPlayer player) {
if (WirelessMagnet.getMode(stack) != WirelessMagnet.Mode.Off) {
WirelessMagnet.doMagnet(stack, player.worldObj, player);
WirelessMagnet.doMagnet(stack, player);
}
}
}
@@ -200,7 +200,7 @@ public class FluidCellInventory implements IFluidCellInventory {
@Override
public long getRemainingFluidTypes() {
final long basedOnStorage = this.getFreeBytes() / this.getBytesPerType();
final long basedOnStorage = this.getFreeBytes() / Math.max(1, this.getBytesPerType());
final long baseOnTotal = this.getTotalFluidTypes() - this.getStoredFluidTypes();
return Math.min(basedOnStorage, baseOnTotal);
}
@@ -71,7 +71,7 @@ public abstract class BaseWirelessInventory extends MEMonitorHandler implements
private void readFromNBT() {
NBTTagCompound data = Platform.openNbtData(this.target);
this.setMagnetCardMode(WirelessMagnet.Mode.values()[data.getInteger(modeKey)]);
this.setMagnetCardMode(WirelessMagnet.Mode.getModes()[data.getInteger(modeKey)]);
this.setRestock(data.getBoolean(ItemBaseWirelessTerminal.restockItems));
}
@@ -137,9 +137,8 @@ public abstract class BaseWirelessInventory extends MEMonitorHandler implements
}
public void setMagnetCardNextMode() {
setMagnetCardMode(
WirelessMagnet.Mode.values()[(getMagnetCardMode().ordinal() + 1)
% WirelessMagnet.Mode.values().length]);
final WirelessMagnet.Mode[] MODES = WirelessMagnet.Mode.getModes();
setMagnetCardMode(MODES[(getMagnetCardMode().ordinal() + 1) % MODES.length]);
}
public void setRestock(boolean val) {
@@ -2,7 +2,6 @@ package com.glodblock.github.inventory.item;
import static com.glodblock.github.common.Config.magnetRange;
import java.util.Iterator;
import java.util.List;
import net.minecraft.entity.item.EntityItem;
@@ -12,9 +11,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerPickupXpEvent;
import com.glodblock.github.common.item.ItemWirelessUltraTerminal;
import appeng.entity.EntityFloatingItem;
import appeng.util.Platform;
public class WirelessMagnet {
@@ -24,9 +26,16 @@ public class WirelessMagnet {
public static String filterConfigKey = "MagnetConfig";
public enum Mode {
Off,
Inv,
ME
ME;
private static final Mode[] MODES = Mode.values();
public static Mode[] getModes() {
return MODES;
}
}
public enum ListMode {
@@ -34,7 +43,7 @@ public class WirelessMagnet {
BlackList
}
public static List<?> getEntitiesInRange(Class<?> entityType, World world, int x, int y, int z, int distance) {
private static <T> List<T> getEntitiesInRange(Class<T> entityType, World world, int x, int y, int z, int distance) {
return world.getEntitiesWithinAABB(
entityType,
AxisAlignedBB.getBoundingBox(
@@ -46,75 +55,87 @@ public class WirelessMagnet {
z + distance));
}
@SuppressWarnings("unchecked")
public static boolean isConfigured(ItemStack wirelessTerm) {
NBTTagCompound data = Platform.openNbtData(wirelessTerm);
return data.hasKey(modeKey);
}
public static void doMagnet(ItemStack wirelessTerm, World world, EntityPlayer player) {
if (wirelessTerm == null || player == null || player.isSneaking() || !isConfigured(wirelessTerm)) return;
Iterator<?> iterator = getEntitiesInRange(
// 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 List<EntityItem> items = getEntitiesInRange(
EntityItem.class,
world,
(int) player.posX,
(int) player.posY,
(int) player.posZ,
magnetRange).iterator();
magnetRange);
final boolean skipPlayerCheck = world.playerEntities.size() < 2;
boolean playSound = false;
while (iterator.hasNext()) {
EntityItem itemToGet = (EntityItem) iterator.next();
EntityPlayer closestPlayer = world.getClosestPlayerToEntity(itemToGet, magnetRange);
if (closestPlayer != null && closestPlayer == player) {
NBTTagCompound itemNBT = new NBTTagCompound();
itemToGet.writeEntityToNBT(itemNBT);
if (itemToGet.func_145800_j() == null
|| !itemToGet.func_145800_j().equals(player.getCommandSenderName()))
itemToGet.delayBeforeCanPickup = 0;
if (itemToGet.delayBeforeCanPickup <= 0) {
itemNBT.setBoolean("attractable", true);
itemToGet.readEntityFromNBT(itemNBT);
}
if (itemNBT.getBoolean("attractable")) {
itemToGet.motionX = itemToGet.motionY = itemToGet.motionZ = 0;
itemToGet.setPosition(
player.posX - 0.2 + (world.rand.nextDouble() * 0.4),
player.posY - 0.6,
player.posZ - 0.2 + (world.rand.nextDouble() * 0.4));
}
for (EntityItem itemToGet : items) {
if (itemToGet.getEntityItem() == null || itemToGet instanceof EntityFloatingItem) {
continue;
}
if (!skipPlayerCheck) {
EntityPlayer closestPlayer = world.getClosestPlayerToEntity(itemToGet, magnetRange);
if (closestPlayer == null || closestPlayer != player) continue;
}
if (itemToGet.delayBeforeCanPickup > 0) {
itemToGet.delayBeforeCanPickup = 0;
}
playSound = true;
itemToGet.motionX = 0;
itemToGet.motionY = 0;
itemToGet.motionZ = 0;
// account for the server/client desync
double playerEyesPos = player.posY
+ (world.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight());
itemToGet.setPosition(
player.posX - 0.2 + (world.rand.nextDouble() * 0.4),
playerEyesPos - 0.62,
player.posZ - 0.2 + (world.rand.nextDouble() * 0.4));
}
// xp
iterator = getEntitiesInRange(
EntityXPOrb.class,
world,
(int) player.posX,
(int) player.posY,
(int) player.posZ,
magnetRange).iterator();
while (iterator.hasNext()) {
EntityXPOrb xpToGet = (EntityXPOrb) iterator.next();
EntityPlayer closestPlayer = world.getClosestPlayerToEntity(xpToGet, magnetRange);
if (playSound) {
world.playSoundAtEntity(
player,
"random.orb",
0.1F,
0.5F * ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 2F));
}
if (!xpToGet.isDead && !xpToGet.isInvisible() && closestPlayer != null && closestPlayer == player) {
int xpAmount = xpToGet.xpValue;
xpToGet.xpValue = 0;
player.xpCooldown = 0;
player.addExperience(xpAmount);
xpToGet.setDead();
xpToGet.setInvisible(true);
world.playSoundAtEntity(
player,
"random.orb",
0.08F,
0.5F * ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.8F));
if (!world.isRemote) {
// 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();
}
}
}
}
@@ -123,7 +144,7 @@ public class WirelessMagnet {
if (is != null && is.getItem() instanceof ItemWirelessUltraTerminal) {
NBTTagCompound data = Platform.openNbtData(is);
if (data.hasKey(modeKey)) {
return Mode.values()[data.getInteger(modeKey)];
return Mode.getModes()[data.getInteger(modeKey)];
}
setMode(is, Mode.Off);
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 494 B

After

Width:  |  Height:  |  Size: 581 B