Skip to content

Commit

Permalink
Cherrypick #463 and #450 (#464)
Browse files Browse the repository at this point in the history
* Fixes (#463)

* refactor: avoid checking release predicate for already stopped sounds

* fix: machines can now be silenced/muffled

* feat: add tooltip infos to item pipes

* fix: machine controller cover was using wrong redstone side

* fix: only call setMuffled() on server side

* refactor: remove unnecessary check for isRemote() in clientTick()

* chore: bump version & update changelog

* thread safe `onChanged` (#450)

Co-authored-by: Mikerooni <[email protected]>

* chore: update changelog

---------

Co-authored-by: KilaBash <[email protected]>
  • Loading branch information
mikerooni and Yefancy authored Oct 10, 2023
1 parent 1d3bc20 commit e2ecc32
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 30 deletions.
13 changes: 6 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# ChangeLog

* add item pipes
* add long distance pipelines
* fix crash when joining servers
* fix pipe covers not having collision
* add oilsands veins
* fix machines sometimes losing NBT
* fix large mixer using the wrong casing
* add tooltip to item pipes
* fix small distillery recipes missing
* fix multi smelter being able to run centrifuge recipes
* fix machines not being silenced/muffled when right-clicking with a hammer
* fix machine controller using the redstone signal from adjacent block's wrong side
* fix onChanged() not being thread-safe
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ public ManagedFieldHolder getFieldHolder() {

@Override
public void onChanged() {
setChanged();
var level = getLevel();
if (level != null && !level.isClientSide && level.getServer() != null) {
level.getServer().execute(this::setChanged);
}
}


@Override
public long getOffsetTimer() {
return level == null ? offset : (level.getGameTime() + offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public ManagedFieldHolder getFieldHolder() {

@Override
public void onChanged() {
coverHolder.markDirty();
var level = coverHolder.getLevel();
if (level != null && !level.isClientSide && level.getServer() != null) {
level.getServer().execute(coverHolder::markDirty);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public ManagedFieldHolder getFieldHolder() {

@Override
public void onChanged() {
markDirty();
var level = getLevel();
if (level != null && !level.isClientSide && level.getServer() != null) {
level.getServer().execute(this::markDirty);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ public ManagedFieldHolder getFieldHolder() {

@Override
public void onChanged() {
markDirty();
var level = getLevel();
if (level != null && !level.isClientSide && level.getServer() != null) {
level.getServer().execute(this::markDirty);
}
}

public Level getLevel() {
Expand All @@ -132,7 +135,7 @@ public Level getLevel() {
public BlockPos getPos() {
return holder.pos();
}

public BlockState getBlockState() {
return holder.getSelf().getBlockState();
}
Expand Down Expand Up @@ -295,8 +298,9 @@ public final InteractionResult onToolClick(@NotNull GTToolType toolType, ItemSta
protected InteractionResult onHardHammerClick(Player playerIn, InteractionHand hand, Direction gridSide, BlockHitResult hitResult) {
if (this instanceof IMufflableMachine mufflableMachine) {
if (!isRemote()) {
mufflableMachine.setMuffled(mufflableMachine.isMuffled());
mufflableMachine.setMuffled(!mufflableMachine.isMuffled());
}

return InteractionResult.CONSUME;
}
return InteractionResult.PASS;
Expand Down Expand Up @@ -552,7 +556,7 @@ public FluidTransferList getFluidTransferCap(@Nullable Direction side) {
}
return null;
}

//////////////////////////////////////
//******** GUI *********//
//////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public abstract class WorkableTieredMachine extends TieredEnergyMachine implemen
public final NotifiableFluidTank exportFluids;
@Getter
protected final Table<IO, RecipeCapability<?>, List<IRecipeHandler<?>>> capabilitiesProxy;
@Persisted
@Getter
@Persisted @Getter
protected int overclockTier;
protected final List<ISubscription> traitSubscriptions;
@Persisted @DescSynced @Getter @Setter
protected boolean isMuffled;
protected boolean previouslyMuffled = true;

public WorkableTieredMachine(IMachineBlockEntity holder, int tier, Int2LongFunction tankScalingFunction, Object... args) {
super(holder, tier, args);
Expand Down Expand Up @@ -195,6 +195,16 @@ public long getOverclockVoltage() {
//****** RECIPE LOGIC *******//
//////////////////////////////////////

@Override
public void clientTick() {
if (previouslyMuffled != isMuffled) {
previouslyMuffled = isMuffled;

if (recipeLogic != null)
recipeLogic.updateSound();
}
}

@Override
public boolean keepSubscribing() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public abstract class WorkableMultiblockMachine extends MultiblockControllerMach
protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(WorkableMultiblockMachine.class, MultiblockControllerMachine.MANAGED_FIELD_HOLDER);
@Nullable @Getter @Setter
private ICleanroomProvider cleanroom;
@Getter
@Persisted
@DescSynced
@Getter @Persisted @DescSynced
public final RecipeLogic recipeLogic;
@Getter
private final GTRecipeType[] recipeTypes;
Expand All @@ -58,6 +56,7 @@ public abstract class WorkableMultiblockMachine extends MultiblockControllerMach
protected final List<ISubscription> traitSubscriptions;
@Getter @Setter @Persisted @DescSynced
protected boolean isMuffled;
protected boolean previouslyMuffled = true;
@Nullable @Getter
protected LongSet activeBlocks;

Expand Down Expand Up @@ -161,6 +160,16 @@ public void onPartUnload() {
//****** RECIPE LOGIC *******//
//////////////////////////////////////

@Override
public void clientTick() {
if (previouslyMuffled != isMuffled) {
previouslyMuffled = isMuffled;

if (recipeLogic != null)
recipeLogic.updateSound();
}
}

@Nullable
@Override
public final GTRecipe modifyRecipe(GTRecipe recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@
@MethodsReturnNonnullByDefault
public abstract class SteamWorkableMachine extends SteamMachine implements IRecipeLogicMachine, IMufflableMachine {
protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(SteamWorkableMachine.class, SteamMachine.MANAGED_FIELD_HOLDER);
@Nullable
@Getter @Setter
@Nullable @Getter @Setter
private ICleanroomProvider cleanroom;
@Getter
@Persisted
@DescSynced
@Getter @Persisted @DescSynced
public final RecipeLogic recipeLogic;
@Getter
public final GTRecipeType[] recipeTypes;
Expand All @@ -62,6 +59,7 @@ public abstract class SteamWorkableMachine extends SteamMachine implements IReci
protected Direction outputFacing;
@Persisted @DescSynced @Getter @Setter
protected boolean isMuffled;
protected boolean previouslyMuffled = true;
@Getter
protected final Table<IO, RecipeCapability<?>, List<IRecipeHandler<?>>> capabilitiesProxy;
protected final List<ISubscription> traitSubscriptions;
Expand Down Expand Up @@ -141,6 +139,16 @@ public GTRecipeType getRecipeType() {
return recipeTypes[activeRecipeType];
}

@Override
public void clientTick() {
if (previouslyMuffled != isMuffled) {
previouslyMuffled = isMuffled;

if (recipeLogic != null)
recipeLogic.updateSound();
}
}

//////////////////////////////////////
//******* Rendering ********//
//////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final boolean hasCapability(@Nullable Direction side) {

@Override
public void onChanged() {
machine.markDirty();
machine.onChanged();
}

public void onMachineLoad() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public ManagedFieldHolder getFieldHolder() {

@Override
public void onChanged() {
markDirty();
var level = getLevel();
if (level != null && !level.isClientSide && level.getServer() != null) {
level.getServer().execute(this::markDirty);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected AutoReleasedSound(SoundEntry soundEntry, BooleanSupplier predicate, Bl

@Override
public void tick() {
if (!predicate.getAsBoolean()) {
if (!isStopped() && !predicate.getAsBoolean()) {
release();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
import com.gregtechceu.gtceu.api.block.MaterialPipeBlock;
import com.gregtechceu.gtceu.api.blockentity.PipeBlockEntity;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.ItemPipeProperties;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
import com.gregtechceu.gtceu.client.model.PipeModel;
import com.gregtechceu.gtceu.common.data.GTBlockEntities;
import com.gregtechceu.gtceu.common.pipelike.item.ItemPipeData;
import com.gregtechceu.gtceu.common.pipelike.item.ItemPipeType;
import com.gregtechceu.gtceu.common.pipelike.item.LevelItemPipeNet;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.entity.BlockEntityType;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ItemPipeBlock extends MaterialPipeBlock<ItemPipeType, ItemPipeData, LevelItemPipeNet> {
public ItemPipeBlock(Properties properties, ItemPipeType itemPipeType, Material material) {
Expand All @@ -36,4 +44,18 @@ public LevelItemPipeNet getWorldPipeNet(ServerLevel level) {
public BlockEntityType<? extends PipeBlockEntity<ItemPipeType, ItemPipeData>> getBlockEntityType() {
return GTBlockEntities.ITEM_PIPE.get();
}

@Override
public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List<Component> tooltip, TooltipFlag flag) {
super.appendHoverText(stack, level, tooltip, flag);
ItemPipeProperties properties = pipeType.modifyProperties(createRawData(defaultBlockState(), stack)).properties();

if (properties.getTransferRate() % 1 != 0) {
tooltip.add(Component.translatable("gtceu.universal.tooltip.item_transfer_rate", (int) ((properties.getTransferRate() * 64) + 0.5)));
} else {
tooltip.add(Component.translatable("gtceu.universal.tooltip.item_transfer_rate_stacks", (int) properties.getTransferRate()));
}

tooltip.add(Component.translatable("gtceu.item_pipe.priority", properties.getPriority()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private int getInputSignal() {
Level level = coverHolder.getLevel();
BlockPos sourcePos = coverHolder.getPos().relative(attachedSide);

return level.getBlockState(sourcePos).getSignal(level, sourcePos, attachedSide.getOpposite());
return level.getBlockState(sourcePos).getSignal(level, sourcePos, attachedSide);
}


Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx6G
# Mod Info
mod_id = gtceu
mod_name = GregTech
mod_version = 1.0.13
mod_version = 1.0.13.a
mod_description = GregTech CE Unofficial, ported from 1.12.2
mod_license = LGPL-3.0 license
mod_url = https://github.com/GregTechCEu/GregTech-Modern/
Expand Down

0 comments on commit e2ecc32

Please sign in to comment.