Skip to content

Commit

Permalink
Fix Issues with Filter Label and MTE Owner Overloads (GregTechCEu#2613)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude authored Sep 12, 2024
1 parent 18672ff commit e086960
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
19 changes: 12 additions & 7 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import gregtech.api.util.Mods;
import gregtech.client.renderer.texture.Textures;
import gregtech.client.utils.BloomEffectUtil;
import gregtech.client.utils.TooltipHelper;
import gregtech.common.ConfigHolder;
import gregtech.common.creativetab.GTCreativeTabs;
import gregtech.common.items.MetaItems;
Expand Down Expand Up @@ -162,7 +163,8 @@ public abstract class MetaTileEntity implements ISyncedTileEntity, CoverHolder,
private int playSoundCooldown = 0;
private int lastTick = 0;

private UUID owner;
@Nullable
private UUID owner = null;

protected MetaTileEntity(@NotNull ResourceLocation metaTileEntityId) {
this.metaTileEntityId = metaTileEntityId;
Expand Down Expand Up @@ -927,13 +929,14 @@ public void getDrops(@NotNull List<@NotNull ItemStack> dropsList, @Nullable Enti

public final ItemStack getPickItem(CuboidRayTraceResult result, EntityPlayer player) {
IndexedCuboid6 hitCuboid = result.cuboid6;
final boolean isCreativePickBlock = player.isCreative() && TooltipHelper.isCtrlDown();
if (hitCuboid.data instanceof CoverRayTracer.CoverSideData coverSideData) {
Cover cover = getCoverAtSide(coverSideData.side);
return cover == null ? ItemStack.EMPTY : cover.getPickItem();
return cover == null || isCreativePickBlock ? ItemStack.EMPTY : cover.getPickItem();
} else if (hitCuboid.data == null || hitCuboid.data instanceof CoverRayTracer.PrimaryBoxData) {
// data is null -> MetaTileEntity hull hit
Cover cover = getCoverAtSide(result.sideHit);
if (cover != null) {
if (cover != null && !isCreativePickBlock) {
return cover.getPickItem();
}
return getPickItem(player);
Expand Down Expand Up @@ -1302,7 +1305,8 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) {

data.setBoolean(TAG_KEY_MUFFLED, muffled);

data.setUniqueId("Owner", owner);
if (owner != null)
data.setUniqueId("Owner", owner);

return data;
}
Expand Down Expand Up @@ -1330,7 +1334,8 @@ public void readFromNBT(NBTTagCompound data) {
CoverSaveHandler.readCoverNBT(data, this, covers::put);
this.muffled = data.getBoolean(TAG_KEY_MUFFLED);

this.owner = data.getUniqueId("Owner");
if (data.hasKey("Owner"))
this.owner = data.getUniqueId("Owner");
}

@Override
Expand Down Expand Up @@ -1378,8 +1383,8 @@ public void onPlacement(@Nullable EntityLivingBase placer) {
* If placing an MTE with methods such as {@link World#setBlockState(BlockPos, IBlockState)},
* this should be manually called immediately afterwards
*/
public void onPlacement() {
this.owner = null;
public final void onPlacement() {
onPlacement(null);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/gregtech/common/covers/CoverFluidFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import gregtech.api.util.GTLog;
import gregtech.api.util.GTUtility;
import gregtech.client.renderer.texture.cube.SimpleOverlayRenderer;
import gregtech.client.utils.TooltipHelper;
import gregtech.common.covers.filter.BaseFilter;
import gregtech.common.covers.filter.BaseFilterContainer;
import gregtech.common.covers.filter.FluidFilterContainer;

import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -77,9 +77,6 @@ public void onAttachment(@NotNull CoverableView coverableView, @NotNull EnumFaci

@Override
public @NotNull ItemStack getPickItem() {
if (TooltipHelper.isCtrlDown())
return getCoverableView().getStackForm();

return this.fluidFilterContainer.getFilterStack();
}

Expand Down Expand Up @@ -107,11 +104,15 @@ public FluidFilterMode getFilterMode() {
return filterMode;
}

@SuppressWarnings("DataFlowIssue") // this cover always has a filter
public @NotNull BaseFilter getFilter() {
return this.fluidFilterContainer.hasFilter() ?
this.fluidFilterContainer.getFilter() :
BaseFilter.ERROR_FILTER;
var filter = getFilterContainer().getFilter();
if (filter == null) return BaseFilter.ERROR_FILTER;

return filter;
}

public @NotNull BaseFilterContainer getFilterContainer() {
return this.fluidFilterContainer;
}

@Override
Expand Down Expand Up @@ -143,11 +144,10 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan

guiSyncManager.syncValue("filtering_mode", filteringMode);
this.fluidFilterContainer.setMaxTransferSize(1);
getFilter().getFilterReader().readStack(this.fluidFilterContainer.getFilterStack());

return getFilter().createPanel(guiSyncManager)
.size(176, 194).padding(7)
.child(CoverWithUI.createTitleRow(getPickItem()))
.child(CoverWithUI.createTitleRow(getFilterContainer().getFilterStack()))
.child(new Column().widthRel(1f).align(Alignment.TopLeft).top(22).coverChildrenHeight()
.child(new EnumRowBuilder<>(FluidFilterMode.class)
.value(filteringMode)
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/gregtech/common/covers/CoverItemFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import gregtech.api.util.GTLog;
import gregtech.api.util.GTUtility;
import gregtech.client.renderer.texture.cube.SimpleOverlayRenderer;
import gregtech.client.utils.TooltipHelper;
import gregtech.common.covers.filter.BaseFilter;
import gregtech.common.covers.filter.BaseFilterContainer;
import gregtech.common.covers.filter.ItemFilterContainer;

import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -70,9 +70,6 @@ public void onAttachment(@NotNull CoverableView coverableView, @NotNull EnumFaci

@Override
public @NotNull ItemStack getPickItem() {
if (TooltipHelper.isCtrlDown())
return getCoverableView().getStackForm();

return this.itemFilterContainer.getFilterStack();
}

Expand Down Expand Up @@ -105,11 +102,15 @@ public ItemFilterMode getFilterMode() {
return filterMode;
}

@SuppressWarnings("DataFlowIssue") // this cover should always have a filter
public @NotNull BaseFilter getFilter() {
return this.itemFilterContainer.hasFilter() ?
this.itemFilterContainer.getFilter() :
BaseFilter.ERROR_FILTER;
var filter = getFilterContainer().getFilter();
if (filter == null) return BaseFilter.ERROR_FILTER;

return filter;
}

public @NotNull BaseFilterContainer getFilterContainer() {
return this.itemFilterContainer;
}

@Override
Expand Down Expand Up @@ -145,11 +146,10 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
var filteringMode = new EnumSyncValue<>(ItemFilterMode.class, this::getFilterMode, this::setFilterMode);

guiSyncManager.syncValue("filtering_mode", filteringMode);
getFilter().getFilterReader().readStack(this.itemFilterContainer.getFilterStack());

return getFilter().createPanel(guiSyncManager)
.size(176, 194).padding(7)
.child(CoverWithUI.createTitleRow(getPickItem()).left(4))
.child(CoverWithUI.createTitleRow(getFilterContainer().getFilterStack()).left(4))
.child(new Column().widthRel(1f).align(Alignment.TopLeft).top(22).coverChildrenHeight()
.child(new EnumRowBuilder<>(ItemFilterMode.class)
.value(filteringMode)
Expand Down

0 comments on commit e086960

Please sign in to comment.