Skip to content

Commit 9756293

Browse files
authored
Merge branch 'master' into relative-dir
2 parents 48368f5 + 92acc6a commit 9756293

File tree

16 files changed

+125
-44
lines changed

16 files changed

+125
-44
lines changed

src/main/java/gregtech/api/metatileentity/NeighborCacheTileEntityBase.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
import org.jetbrains.annotations.NotNull;
1212
import org.jetbrains.annotations.Nullable;
1313

14+
import java.lang.ref.WeakReference;
1415
import java.util.Arrays;
16+
import java.util.List;
1517

1618
public abstract class NeighborCacheTileEntityBase extends SyncedTileEntityBase implements INeighborCache {
1719

18-
private final TileEntity[] neighbors = new TileEntity[6];
20+
private static final WeakReference<TileEntity> NULL = new WeakReference<>(null);
21+
private static final WeakReference<TileEntity> INVALID = new WeakReference<>(null);
22+
23+
private final List<WeakReference<TileEntity>> neighbors = Arrays.asList(
24+
INVALID, INVALID, INVALID, INVALID, INVALID, INVALID);
1925
private boolean neighborsInvalidated = false;
2026

2127
public NeighborCacheTileEntityBase() {
@@ -24,7 +30,9 @@ public NeighborCacheTileEntityBase() {
2430

2531
protected void invalidateNeighbors() {
2632
if (!this.neighborsInvalidated) {
27-
Arrays.fill(this.neighbors, this);
33+
for (EnumFacing value : EnumFacing.VALUES) {
34+
this.neighbors.set(value.getIndex(), INVALID);
35+
}
2836
this.neighborsInvalidated = true;
2937
}
3038
}
@@ -60,17 +68,34 @@ public void onChunkUnload() {
6068
@Override
6169
public @Nullable TileEntity getNeighbor(@NotNull EnumFacing facing) {
6270
if (world == null || pos == null) return null;
63-
int i = facing.getIndex();
64-
TileEntity neighbor = this.neighbors[i];
65-
if (neighbor == this || (neighbor != null && neighbor.isInvalid())) {
66-
neighbor = world.getTileEntity(pos.offset(facing));
67-
this.neighbors[i] = neighbor;
68-
this.neighborsInvalidated = false;
69-
}
70-
return neighbor;
71+
// if the ref is INVALID, compute neighbor, otherwise, return TE or null
72+
WeakReference<TileEntity> ref = invalidRef(facing) ? computeNeighbor(facing) : getRef(facing);
73+
return ref.get();
74+
}
75+
76+
private boolean invalidRef(EnumFacing facing) {
77+
WeakReference<TileEntity> ref = getRef(facing);
78+
if (ref == INVALID) return true;
79+
TileEntity te = ref.get();
80+
return te != null && te.isInvalid();
81+
}
82+
83+
@NotNull
84+
private WeakReference<TileEntity> computeNeighbor(EnumFacing facing) {
85+
TileEntity te = super.getNeighbor(facing);
86+
// avoid making new references to null TEs
87+
WeakReference<TileEntity> ref = te == null ? NULL : new WeakReference<>(te);
88+
this.neighbors.set(facing.getIndex(), ref);
89+
this.neighborsInvalidated = false;
90+
return ref;
91+
}
92+
93+
@NotNull
94+
private WeakReference<TileEntity> getRef(EnumFacing facing) {
95+
return this.neighbors.get(facing.getIndex());
7196
}
7297

7398
public void onNeighborChanged(@NotNull EnumFacing facing) {
74-
this.neighbors[facing.getIndex()] = this;
99+
this.neighbors.set(facing.getIndex(), INVALID);
75100
}
76101
}

src/main/java/gregtech/api/pipenet/block/BlockPipe.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ public BlockFaceShape getBlockFaceShape(@NotNull IBlockAccess worldIn, @NotNull
564564
}
565565

566566
@Override
567-
public boolean recolorBlock(World world, @NotNull BlockPos pos, @NotNull EnumFacing side,
567+
public boolean recolorBlock(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing side,
568568
@NotNull EnumDyeColor color) {
569-
IPipeTile<PipeType, NodeDataType> tileEntityPipe = (IPipeTile<PipeType, NodeDataType>) world.getTileEntity(pos);
569+
IPipeTile<PipeType, NodeDataType> tileEntityPipe = getPipeTileEntity(world, pos);
570570
if (tileEntityPipe != null && tileEntityPipe.getPipeType() != null &&
571571
tileEntityPipe.getPipeType().isPaintable() &&
572572
tileEntityPipe.getPaintingColor() != color.colorValue) {
@@ -588,6 +588,7 @@ public IPipeTile<PipeType, NodeDataType> getPipeTileEntity(IBlockAccess world, B
588588
return getPipeTileEntity(tileEntityAtPos);
589589
}
590590

591+
@Nullable
591592
public IPipeTile<PipeType, NodeDataType> getPipeTileEntity(TileEntity tileEntityAtPos) {
592593
if (tileEntityAtPos instanceof IPipeTile &&
593594
isThisPipeBlock(((IPipeTile<PipeType, NodeDataType>) tileEntityAtPos).getPipeBlock())) {

src/main/java/gregtech/api/util/input/KeyBind.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public enum KeyBind {
3838
VANILLA_RIGHT(() -> () -> Minecraft.getMinecraft().gameSettings.keyBindRight),
3939
ARMOR_MODE_SWITCH("gregtech.key.armor_mode_switch", KeyConflictContext.IN_GAME, Keyboard.KEY_M),
4040
ARMOR_HOVER("gregtech.key.armor_hover", KeyConflictContext.IN_GAME, Keyboard.KEY_H),
41+
ARMOR_CANCEL_INERTIA("gregtech.key.armor_cancel_inertia", KeyConflictContext.IN_GAME, Keyboard.KEY_I),
4142
ARMOR_CHARGING("gregtech.key.armor_charging", KeyConflictContext.IN_GAME, Keyboard.KEY_N),
4243
TOOL_AOE_CHANGE("gregtech.key.tool_aoe_change", KeyConflictContext.IN_GAME, Keyboard.KEY_V);
4344

src/main/java/gregtech/common/covers/ender/CoverAbstractEnderLink.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ protected IWidget createIoRow() {
212212
.coverChildrenHeight()
213213
.child(new ToggleButton()
214214
.value(new BooleanSyncValue(this::isIoEnabled, this::setIoEnabled))
215-
.overlay(IKey.dynamic(() -> IKey.lang(this.ioEnabled ?
215+
.overlay(IKey.lang(() -> this.ioEnabled ?
216216
"behaviour.soft_hammer.enabled" :
217-
"behaviour.soft_hammer.disabled").get())
217+
"behaviour.soft_hammer.disabled")
218218
.color(Color.WHITE.darker(1)))
219219
.widthRel(0.6f)
220220
.left(0));

src/main/java/gregtech/common/covers/filter/BaseFilterContainer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public boolean isItemValid(int slot, @NotNull ItemStack stack) {
9797

9898
protected abstract boolean isItemValid(ItemStack stack);
9999

100-
protected abstract String getFilterName();
100+
protected abstract @NotNull IKey getFilterKey();
101101

102102
@Override
103103
public @NotNull ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
@@ -244,7 +244,7 @@ public IWidget initUI(GuiData data, PanelSyncManager manager) {
244244
}
245245
return true;
246246
}))
247-
.child(IKey.dynamic(this::getFilterName)
247+
.child(getFilterKey()
248248
.color(CoverWithUI.UI_TEXT_COLOR)
249249
.shadow(false)
250250
.alignment(Alignment.CenterRight).asWidget()

src/main/java/gregtech/common/covers/filter/FluidFilterContainer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.cleanroommc.modularui.api.drawable.IKey;
88
import org.jetbrains.annotations.ApiStatus;
9+
import org.jetbrains.annotations.NotNull;
910

1011
import java.util.function.BooleanSupplier;
1112
import java.util.function.Consumer;
@@ -56,9 +57,9 @@ protected boolean isItemValid(ItemStack stack) {
5657
}
5758

5859
@Override
59-
protected String getFilterName() {
60-
return hasFilter() ?
61-
getFilterStack().getDisplayName() :
62-
IKey.lang("metaitem.fluid_filter.name").get();
60+
protected @NotNull IKey getFilterKey() {
61+
return IKey.lang(() -> hasFilter() ?
62+
getFilterStack().getTranslationKey() + ".name" :
63+
"metaitem.fluid_filter.name");
6364
}
6465
}

src/main/java/gregtech/common/covers/filter/ItemFilterContainer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import com.cleanroommc.modularui.api.drawable.IKey;
1212
import org.jetbrains.annotations.ApiStatus;
13+
import org.jetbrains.annotations.NotNull;
1314

1415
import java.util.function.BooleanSupplier;
1516
import java.util.function.Consumer;
@@ -57,9 +58,9 @@ protected boolean isItemValid(ItemStack stack) {
5758
}
5859

5960
@Override
60-
protected String getFilterName() {
61-
return hasFilter() ?
62-
getFilterStack().getDisplayName() :
63-
IKey.lang("metaitem.item_filter.name").get();
61+
protected @NotNull IKey getFilterKey() {
62+
return IKey.lang(() -> hasFilter() ?
63+
getFilterStack().getTranslationKey() + ".name" :
64+
"metaitem.item_filter.name");
6465
}
6566
}

src/main/java/gregtech/common/items/armor/AdvancedJetpack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void onArmorTick(World world, EntityPlayer player, @NotNull ItemStack ite
4444
}
4545
}
4646

47-
performFlying(player, hoverMode, item);
47+
performFlying(player, hoverMode, false, item);
4848

4949
if (toggleTimer > 0) toggleTimer--;
5050

src/main/java/gregtech/common/items/armor/AdvancedNanoMuscleSuite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ else if (canShare)
7676
data.setBoolean("canShare", canShare);
7777
}
7878

79-
performFlying(player, hoverMode, item);
79+
performFlying(player, hoverMode, false, item);
8080

8181
// Charging mechanics
8282
if (canShare && !world.isRemote) {

src/main/java/gregtech/common/items/armor/AdvancedQuarkTechSuite.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public void onArmorTick(World world, EntityPlayer player, ItemStack item) {
4646

4747
NBTTagCompound data = GTUtility.getOrCreateNbtCompound(item);
4848
boolean hoverMode = data.hasKey("hover") && data.getBoolean("hover");
49+
boolean cancelInertiaMode = data.hasKey("cancelInertia") && data.getBoolean("cancelInertia");
4950
byte toggleTimer = data.hasKey("toggleTimer") ? data.getByte("toggleTimer") : 0;
5051
boolean canShare = data.hasKey("canShare") && data.getBoolean("canShare");
5152

@@ -61,6 +62,20 @@ public void onArmorTick(World world, EntityPlayer player, ItemStack item) {
6162
}
6263
}
6364

65+
if (toggleTimer == 0 && KeyBind.ARMOR_CANCEL_INERTIA.isKeyDown(player)) {
66+
cancelInertiaMode = !cancelInertiaMode;
67+
toggleTimer = 5;
68+
data.setBoolean("cancelInertia", cancelInertiaMode);
69+
if (!world.isRemote) {
70+
if (cancelInertiaMode)
71+
player.sendStatusMessage(new TextComponentTranslation("metaarmor.jetpack.cancel_inertia.enable"),
72+
true);
73+
else
74+
player.sendStatusMessage(new TextComponentTranslation("metaarmor.jetpack.cancel_inertia.disable"),
75+
true);
76+
}
77+
}
78+
6479
if (toggleTimer == 0 && KeyBind.ARMOR_CHARGING.isKeyDown(player)) {
6580
canShare = !canShare;
6681
toggleTimer = 5;
@@ -78,7 +93,7 @@ else if (canShare)
7893
data.setBoolean("canShare", canShare);
7994
}
8095

81-
performFlying(player, hoverMode, item);
96+
performFlying(player, hoverMode, cancelInertiaMode, item);
8297

8398
if (player.isBurning())
8499
player.extinguish();
@@ -130,6 +145,7 @@ else if (canShare)
130145
if (toggleTimer > 0) toggleTimer--;
131146

132147
data.setBoolean("canShare", canShare);
148+
data.setBoolean("cancelInertia", cancelInertiaMode);
133149
data.setBoolean("hover", hoverMode);
134150
data.setByte("toggleTimer", toggleTimer);
135151
player.inventoryContainer.detectAndSendChanges();
@@ -157,6 +173,11 @@ public void addInfo(ItemStack itemStack, List<String> lines) {
157173
status = I18n.format("metaarmor.hud.status.enabled");
158174
}
159175
lines.add(I18n.format("metaarmor.hud.hover_mode", status));
176+
if (data.hasKey("cancelInertia")) {
177+
if (data.getBoolean("cancelInertia"))
178+
status = I18n.format("metaarmor.hud.status.enabled");
179+
}
180+
lines.add(I18n.format("metaarmor.hud.cancel_inertia_mode", status));
160181
super.addInfo(itemStack, lines);
161182
}
162183

@@ -210,6 +231,12 @@ public void drawHUD(ItemStack item) {
210231
"metaarmor.hud.status.disabled";
211232
this.HUD.newString(I18n.format("metaarmor.hud.hover_mode", I18n.format(status)));
212233
}
234+
235+
if (data.hasKey("cancelInertia")) {
236+
String status = data.getBoolean("cancelInertia") ? "metaarmor.hud.status.enabled" :
237+
"metaarmor.hud.status.disabled";
238+
this.HUD.newString(I18n.format("metaarmor.hud.cancel_inertia_mode", I18n.format(status)));
239+
}
213240
}
214241
this.HUD.draw();
215242
this.HUD.reset();

0 commit comments

Comments
 (0)