Skip to content

Commit

Permalink
misc fix
Browse files Browse the repository at this point in the history
  • Loading branch information
khjxiaogu committed Jan 21, 2025
1 parent 215b260 commit ffba4d1
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/teammoeg/chorda/menu/CBaseMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.util.function.Predicate;

import com.teammoeg.chorda.ChordaNetwork;
import com.teammoeg.chorda.menu.CCustomMenuSlot.SyncableDataSlot;
import com.teammoeg.chorda.network.ContainerDataSyncMessageS2C;
import com.teammoeg.chorda.network.ContainerOperationMessageC2S;
import com.teammoeg.chorda.util.utility.CCustomMenuSlot.SyncableDataSlot;

import blusunrize.immersiveengineering.common.gui.IEContainerMenu.MoveItemsFunc;
import net.minecraft.core.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package com.teammoeg.chorda.util.utility;
package com.teammoeg.chorda.menu;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

import com.teammoeg.chorda.menu.CBaseMenu;
import com.mojang.serialization.Codec;
import com.teammoeg.chorda.util.io.CodecUtil;
import com.teammoeg.chorda.util.io.SerializeUtil;
import com.teammoeg.chorda.util.io.registry.IdRegistry;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.world.inventory.ContainerData;
import net.minecraft.world.inventory.DataSlot;
import net.minecraftforge.fluids.FluidStack;
Expand Down Expand Up @@ -398,6 +404,35 @@ public boolean isSame(FluidStack data, FluidStack data2) {
static {
encoders.register(SLOT_TANK);
}
public static <T> OtherDataSlotEncoder<T> codec(Codec<T> type,Supplier<T> def,UnaryOperator<T> copy,Comparator<T> comparator){
return new OtherDataSlotEncoder<>(){

@Override
public T read(FriendlyByteBuf network) {
return CodecUtil.readCodec(network, type);
}

@Override
public void write(FriendlyByteBuf network, T data) {
CodecUtil.writeCodec(network, type, data);
}

@Override
public T copy(T data) {
return copy.apply(data);
}

@Override
public T getDefault() {
return def.get();
}
@Override
public boolean isSame(T data, T data2) {
return comparator.compare(data, data2)==0;
}

};
}
public static <T> CDataSlot<T> create(CBaseMenu container, DataSlotConverter<T> type) {
SingleDataSlot<T> slot=new SingleDataSlot<>(type);
container.addDataSlot(slot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.function.Supplier;

import com.teammoeg.chorda.menu.CBaseMenu;
import com.teammoeg.chorda.util.utility.CCustomMenuSlot;
import com.teammoeg.chorda.util.utility.CCustomMenuSlot.OtherDataSlotEncoder;
import com.teammoeg.chorda.menu.CCustomMenuSlot;
import com.teammoeg.chorda.menu.CCustomMenuSlot.OtherDataSlotEncoder;
import com.teammoeg.chorda.util.client.ClientUtils;
import com.teammoeg.chorda.util.io.SerializeUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.Optional;

import com.teammoeg.chorda.menu.CBaseMenu;
import com.teammoeg.chorda.util.utility.CCustomMenuSlot;
import com.teammoeg.chorda.util.utility.CCustomMenuSlot.CDataSlot;
import com.teammoeg.chorda.menu.CCustomMenuSlot;
import com.teammoeg.chorda.menu.CCustomMenuSlot.CDataSlot;
import com.teammoeg.chorda.util.ie.CMultiblockHelper;
import com.teammoeg.chorda.util.client.Point;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ public void tickHeatedProcess(Level world) {
RLevel = ranged / 100F;

}

public boolean hasFuel() {
return process>0||!inventory.getStackInSlot(INPUT_SLOT).isEmpty();
}
public boolean tickFuelProcess(Level w,SpecialDataHolder<?> teamData) {
if (!isWorking || isBroken)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,24 +249,29 @@ public void regist(IMultiblockContext<R> ctx) {
*/
@Override
protected boolean tickFuel(IMultiblockContext<R> ctx) {
R state=ctx.getState();
Optional<GeneratorData> data = getData(ctx);
boolean lastIsBroken = data.map(t -> t.isBroken).orElse(false);

boolean curHasFuel=data.map(t->t.hasFuel()).orElse(false);
if(state.hasFuel!=curHasFuel) {
state.hasFuel=curHasFuel;
ctx.requestMasterBESync();
}
// Tick the GeneratorData
ctx.getState().tickData(ctx.getLevel().getRawLevel(), CMultiblockHelper.getAbsoluteMaster(ctx));
state.tickData(ctx.getLevel().getRawLevel(), CMultiblockHelper.getAbsoluteMaster(ctx));
boolean isActive = data.map(t -> t.isActive).orElse(false);

// If newly broken, start exploding for 100 ticks
boolean isBroken = data.map(t -> t.isBroken).orElse(false);
if (lastIsBroken != isBroken && isBroken) {
ctx.getState().explodeTicks = 100;
state.explodeTicks = 100;
}

Level level = ctx.getLevel().getRawLevel();
if (ctx.getState().explodeTicks > 0) {
if (state.explodeTicks > 0) {
Vec3i size = CMultiblockHelper.getSize(ctx);
// Every 5 ticks, send explosion packet to nearby players
if (ctx.getState().explodeTicks % 5 == 0) {
if (state.explodeTicks % 5 == 0) {
BlockPos pos = ctx.getLevel().toAbsolute(new BlockPos(level.random.nextInt(size.getX()),
level.random.nextInt(size.getY()),
level.random.nextInt(size.getZ())));
Expand All @@ -277,7 +282,7 @@ protected boolean tickFuel(IMultiblockContext<R> ctx) {
}
}
// Reduce the explode ticks
ctx.getState().explodeTicks--;
state.explodeTicks--;
}

// Tick the drives
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ public class GeneratorState extends HeatingState {
* Remaining ticks to explode
*/
int explodeTicks;
public HeatEndpoint ep = new HeatEndpoint(200, 0);
boolean hasFuel;
public boolean hasFuel() {
return hasFuel;
}

public void setHasFuel(boolean hasFuel) {
this.hasFuel = hasFuel;
}

public HeatEndpoint ep = new HeatEndpoint(200, 0);
public GeneratorState() {
super();
}
Expand Down Expand Up @@ -118,4 +127,16 @@ public void onDataChange() {

}

@Override
public void writeSyncNBT(CompoundTag nbt) {
super.writeSyncNBT(nbt);
nbt.putBoolean("hasFuel", hasFuel);
}

@Override
public void readSyncNBT(CompoundTag nbt) {
super.readSyncNBT(nbt);
hasFuel=nbt.getBoolean("hasFuel");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ public void render(MultiblockBlockEntityMaster<T1GeneratorState> blockEntity, fl
final IMultiblockBEHelperMaster<T1GeneratorState> helper = blockEntity.getHelper();
final T1GeneratorState state = helper.getState();
final MultiblockOrientation orientation = helper.getContext().getLevel().getOrientation();
BlockPos blockPos = blockEntity.getBlockPos();

if (state.getData(blockPos).map(t -> !t.inventory.getStackInSlot(GeneratorData.INPUT_SLOT).isEmpty()).orElse(false)) {
if (state.hasFuel()) {
matrixStack.pushPose();
bufferIn = BERenderUtils.mirror(orientation, matrixStack, bufferIn);
Direction facing = orientation.front();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
package com.teammoeg.frostedheart.content.climate.heatdevice.generator.t2;

import com.teammoeg.frostedheart.content.climate.heatdevice.generator.GeneratorContainer;
import com.teammoeg.chorda.util.utility.CCustomMenuSlot;
import com.teammoeg.chorda.util.utility.CCustomMenuSlot.CDataSlot;
import com.teammoeg.chorda.menu.CCustomMenuSlot;
import com.teammoeg.chorda.menu.CCustomMenuSlot.CDataSlot;
import com.teammoeg.chorda.util.client.Point;

import blusunrize.immersiveengineering.common.gui.IEContainerMenu.MultiblockMenuContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ public void render(MultiblockBlockEntityMaster<T2GeneratorState> blockEntity, fl
final IMultiblockBEHelperMaster<T2GeneratorState> helper = blockEntity.getHelper();
final T2GeneratorState state = helper.getState();
final MultiblockOrientation orientation = helper.getContext().getLevel().getOrientation();
BlockPos blockPos = blockEntity.getBlockPos();

if (state.getData(blockPos).map(t -> !t.inventory.getStackInSlot(GeneratorData.INPUT_SLOT).isEmpty()).orElse(false)) {
if (state.hasFuel()) {
matrixStack.pushPose();
bufferIn = BERenderUtils.mirror(orientation, matrixStack, bufferIn);
Direction facing = orientation.front();
Expand Down

0 comments on commit ffba4d1

Please sign in to comment.