Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.19.2' into 1.20.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/scala/com/yogpc/qp/machines/marker/FlexMarkerMessage.java
#	src/main/scala/com/yogpc/qp/machines/marker/Marker16Message.java
#	src/main/scala/com/yogpc/qp/machines/marker/Tile16Marker.java
#	src/main/scala/com/yogpc/qp/machines/misc/CreativeGeneratorMenu.java
#	src/main/scala/com/yogpc/qp/machines/misc/CreativeGeneratorScreen.java
#	src/main/scala/com/yogpc/qp/machines/misc/CreativeGeneratorTile.java
#	src/main/scala/com/yogpc/qp/machines/workbench/TileWorkbench.java
#	src/main/scala/com/yogpc/qp/packet/TileMessage.java
#	temp_changelog.md
  • Loading branch information
Kotori316 committed Jan 20, 2024
2 parents ef2ca3d + 516e2dc commit 65e8ca6
Show file tree
Hide file tree
Showing 23 changed files with 239 additions and 136 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
id("com.github.breadmoirai.github-release") version("2.4.1")
id("com.matthewprenger.cursegradle") version("1.4.0")
id("com.modrinth.minotaur").version("2.+")
id("com.kotori316.plugin.cf").version("2.2")
id("com.kotori316.plugin.cf").version("2.3")
}
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.

Expand Down Expand Up @@ -565,6 +565,7 @@ tasks.register("registerVersion", CallVersionFunctionTask.class) {
functionEndpoint = readVersionFunctionEndpoint(project)
gameVersion = project.findProperty("minecraftVersion")
platform = "forge"
platformVersion = project.findProperty("forgeVersion") as String
modName = "quarryplus"
changelog = getShortChangelog(false)
homepage = "https://www.curseforge.com/minecraft/mc-mods/additional-enchanted-miner"
Expand Down
27 changes: 14 additions & 13 deletions src/main/scala/com/yogpc/qp/machines/advpump/TileAdvPump.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,36 @@ public TileAdvPump(BlockPos pos, BlockState state) {
@Override
public void saveNbtData(CompoundTag nbt) {
nbt.put("storage", storage.toNbt());
toClientTag(nbt);
nbt.put("moduleInventory", moduleInventory.serializeNBT());
}

@Override
public CompoundTag toClientTag(CompoundTag nbt) {
nbt.putInt("y", y);
nbt.put("enchantments", enchantmentEfficiency.toNbt());
nbt.putBoolean("finished", finished);
nbt.putBoolean("deleteFluid", deleteFluid);
nbt.putBoolean("placeFrame", placeFrame);
nbt.put("moduleInventory", moduleInventory.serializeNBT());
return nbt;
}

@Override
public void load(CompoundTag nbt) {
super.load(nbt);
storage.readNbt(nbt.getCompound("storage"));
fromClientTag(nbt);
moduleInventory.deserializeNBT(nbt.getCompound("moduleInventory"));
isBlockModuleLoaded = false;
}

@Override
public void fromClientTag(CompoundTag nbt) {
y = nbt.getInt("y");
setEnchantment(EnchantmentEfficiency.fromNbt(nbt.getCompound("enchantments")));
finished = nbt.getBoolean("finished");
deleteFluid = nbt.getBoolean("deleteFluid");
placeFrame = nbt.getBoolean("placeFrame");
moduleInventory.deserializeNBT(nbt.getCompound("moduleInventory"));
isBlockModuleLoaded = false;
}

public static void tick(Level world, BlockPos pos, BlockState state, TileAdvPump pump) {
Expand Down Expand Up @@ -231,16 +242,6 @@ public List<? extends Component> getDebugLogs() {
).map(Component::literal)).toList();
}

@Override
public void fromClientTag(CompoundTag tag) {
load(tag);
}

@Override
public CompoundTag toClientTag(CompoundTag tag) {
return saveWithoutMetadata();
}

public void sync() {
if (level != null && !level.isClientSide)
PacketHandler.sendToClient(new ClientSyncMessage(this), level);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.yogpc.qp.machines.marker;

import com.yogpc.qp.packet.ClientSyncMessage;
import com.yogpc.qp.packet.IMessage;
import com.yogpc.qp.packet.PacketHandler;
import com.yogpc.qp.packet.TileMessage;
import com.yogpc.qp.utils.MapMulti;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
Expand Down Expand Up @@ -51,7 +51,7 @@ public static void onReceive(FlexMarkerMessage message, Supplier<NetworkEvent.Co
.flatMap(MapMulti.optCast(TileFlexMarker.class))
.ifPresent(m -> {
m.move(message.movable, message.amount);
PacketHandler.sendToClient(new TileMessage(m), Objects.requireNonNull(m.getLevel()));
PacketHandler.sendToClient(new ClientSyncMessage(m), Objects.requireNonNull(m.getLevel()));
}));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.yogpc.qp.machines.marker;

import com.yogpc.qp.packet.ClientSyncMessage;
import com.yogpc.qp.packet.IMessage;
import com.yogpc.qp.packet.PacketHandler;
import com.yogpc.qp.packet.TileMessage;
import com.yogpc.qp.utils.MapMulti;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
Expand Down Expand Up @@ -56,7 +56,7 @@ public static void onReceive(Marker16Message message, Supplier<NetworkEvent.Cont
.flatMap(MapMulti.optCast(Tile16Marker.class))
.ifPresent(m -> {
m.changeSize(message.amount, message.yMax, message.yMin);
PacketHandler.sendToClient(new TileMessage(m), Objects.requireNonNull(m.getLevel()));
PacketHandler.sendToClient(new ClientSyncMessage(m), Objects.requireNonNull(m.getLevel()));
}));
}

Expand Down
15 changes: 14 additions & 1 deletion src/main/scala/com/yogpc/qp/machines/marker/Tile16Marker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.yogpc.qp.machines.Area;
import com.yogpc.qp.machines.CheckerLog;
import com.yogpc.qp.machines.QuarryMarker;
import com.yogpc.qp.packet.ClientSync;
import com.yogpc.qp.render.Box;
import com.yogpc.qp.render.RenderMarker;
import net.minecraft.core.BlockPos;
Expand All @@ -23,7 +24,7 @@
import java.util.Optional;
import java.util.stream.Stream;

public class Tile16Marker extends BlockEntity implements QuarryMarker, CheckerLog {
public class Tile16Marker extends BlockEntity implements QuarryMarker, CheckerLog, ClientSync {
private BlockPos min = BlockPos.ZERO;
private BlockPos max = BlockPos.ZERO;
@Nullable
Expand Down Expand Up @@ -124,4 +125,16 @@ public List<ItemStack> removeAndGetItems() {
level.removeBlock(getBlockPos(), false);
return List.of(new ItemStack(getBlockState().getBlock()));
}

@Override
public void fromClientTag(CompoundTag tag) {
load(tag);
}

@Override
public CompoundTag toClientTag(CompoundTag tag) {
saveAdditional(tag);
return tag;
}

}
14 changes: 13 additions & 1 deletion src/main/scala/com/yogpc/qp/machines/marker/TileFlexMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.yogpc.qp.machines.Area;
import com.yogpc.qp.machines.CheckerLog;
import com.yogpc.qp.machines.QuarryMarker;
import com.yogpc.qp.packet.ClientSync;
import com.yogpc.qp.render.Box;
import com.yogpc.qp.render.RenderMarker;
import net.minecraft.core.BlockPos;
Expand All @@ -24,7 +25,7 @@
import java.util.function.UnaryOperator;
import java.util.stream.Stream;

public class TileFlexMarker extends BlockEntity implements QuarryMarker, CheckerLog {
public class TileFlexMarker extends BlockEntity implements QuarryMarker, CheckerLog, ClientSync {

private BlockPos min;
private BlockPos max;
Expand Down Expand Up @@ -154,6 +155,17 @@ public List<ItemStack> removeAndGetItems() {
return List.of(new ItemStack(getBlockState().getBlock()));
}

@Override
public void fromClientTag(CompoundTag tag) {
load(tag);
}

@Override
public CompoundTag toClientTag(CompoundTag tag) {
saveAdditional(tag);
return tag;
}

public enum Movable {
UP(facing -> Direction.UP),
LEFT(Direction::getCounterClockWise),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.yogpc.qp.Holder;
import com.yogpc.qp.QuarryPlus;
import com.yogpc.qp.machines.*;
import com.yogpc.qp.packet.ClientSync;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
Expand All @@ -26,7 +27,7 @@
import java.util.List;
import java.util.stream.Stream;

public class MiningWellTile extends PowerTile implements CheckerLog, MachineStorage.HasStorage, EnchantmentLevel.HasEnchantments {
public class MiningWellTile extends PowerTile implements CheckerLog, MachineStorage.HasStorage, EnchantmentLevel.HasEnchantments, ClientSync {
private final MachineStorage storage = new MachineStorage();
private final ItemConverter itemConverter = ItemConverter.defaultConverter();
public int digMinY = 0;
Expand Down Expand Up @@ -96,20 +97,31 @@ public void tick() {
@Override
public void saveNbtData(CompoundTag nbt) {
nbt.put("storage", storage.toNbt());
nbt.putInt("digMinY", digMinY);
nbt.putInt("waitingTick", interval);
nbt.putBoolean("finished", finished);
nbt.putInt("efficiencyLevel", efficiencyLevel);
toClientTag(nbt);
}

@Override
public CompoundTag toClientTag(CompoundTag tag) {
tag.putInt("digMinY", digMinY);
tag.putInt("waitingTick", interval);
tag.putBoolean("finished", finished);
tag.putInt("efficiencyLevel", efficiencyLevel);
return tag;
}

@Override
public void load(CompoundTag nbt) {
super.load(nbt);
storage.readNbt(nbt.getCompound("storage"));
digMinY = nbt.getInt("digMinY");
interval = nbt.getInt("waitingTick");
finished = nbt.getBoolean("finished");
efficiencyLevel = nbt.getInt("efficiencyLevel");
fromClientTag(nbt);
}

@Override
public void fromClientTag(CompoundTag tag) {
digMinY = tag.getInt("digMinY");
interval = tag.getInt("waitingTick");
finished = tag.getBoolean("finished");
efficiencyLevel = tag.getInt("efficiencyLevel");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import com.yogpc.qp.Holder;
import com.yogpc.qp.QuarryPlus;
import com.yogpc.qp.packet.ClientSyncMessage;
import com.yogpc.qp.packet.PacketHandler;
import com.yogpc.qp.packet.TileMessage;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

public class CreativeGeneratorMenu extends AbstractContainerMenu {
public static final String GUI_ID = QuarryPlus.modID + ":gui_" + CreativeGeneratorBlock.NAME;
@NotNull
final CreativeGeneratorTile tile;

public CreativeGeneratorMenu(int id, Player player, BlockPos pos) {
Expand All @@ -28,7 +30,7 @@ public CreativeGeneratorMenu(int id, Player player, BlockPos pos) {
this.addSlot(new Slot(player.getInventory(), l, 8 + l * 18, 142));
}
if (!player.level().isClientSide && tile != null) {
PacketHandler.sendToClientPlayer(new TileMessage(tile), (ServerPlayer) player);
PacketHandler.sendToClientPlayer(new ClientSyncMessage(tile), (ServerPlayer) player);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.yogpc.qp.QuarryPlus;
import com.yogpc.qp.machines.PowerTile;
import com.yogpc.qp.packet.PacketHandler;
import com.yogpc.qp.packet.TileMessage;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
Expand Down Expand Up @@ -73,7 +72,7 @@ private void changeEnergy(String s) {
long e = Long.parseLong(s);
if (e >= 0) {
getMenu().tile.sendEnergy = e;
PacketHandler.sendToServer(new TileMessage(getMenu().tile));
PacketHandler.sendToServer(new CreativeGeneratorSyncMessage(getMenu().tile));
}
} catch (NumberFormatException ignore) {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.yogpc.qp.machines.misc;

import com.yogpc.qp.Holder;
import com.yogpc.qp.packet.IMessage;
import com.yogpc.qp.packet.PacketHandler;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import net.minecraftforge.network.NetworkEvent;

import java.util.function.Supplier;

/**
* To server only
*/
public final class CreativeGeneratorSyncMessage implements IMessage {

private final BlockPos pos;
private final ResourceKey<Level> dim;
private final long sendEnergy;

CreativeGeneratorSyncMessage(BlockPos pos, ResourceKey<Level> dim, long sendEnergy) {
this.pos = pos;
this.dim = dim;
this.sendEnergy = sendEnergy;
}

CreativeGeneratorSyncMessage(CreativeGeneratorTile tile) {
this(tile.getBlockPos(), PacketHandler.getDimension(tile), tile.sendEnergy);
}

public CreativeGeneratorSyncMessage(FriendlyByteBuf buf) {
this(
buf.readBlockPos(),
ResourceKey.create(Registry.DIMENSION_REGISTRY, buf.readResourceLocation()),
buf.readLong()
);
}

@Override
public void write(FriendlyByteBuf buf) {
buf.writeBlockPos(pos).writeResourceLocation(dim.location());
buf.writeLong(sendEnergy);
}

public static void onReceive(CreativeGeneratorSyncMessage message, Supplier<NetworkEvent.Context> supplier) {
var world = PacketHandler.getWorld(supplier.get(), message.pos, message.dim);
supplier.get().enqueueWork(() ->
world.flatMap(l -> l.getBlockEntity(message.pos, Holder.CREATIVE_GENERATOR_TYPE))
.ifPresent(t -> t.sendEnergy = message.sendEnergy)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.yogpc.qp.Holder;
import com.yogpc.qp.machines.PowerTile;
import com.yogpc.qp.packet.ClientSync;
import com.yogpc.qp.utils.MapMulti;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -16,7 +17,7 @@

import java.util.Arrays;

public class CreativeGeneratorTile extends PowerTile implements MenuProvider {
public class CreativeGeneratorTile extends PowerTile implements MenuProvider, ClientSync {
long sendEnergy = ONE_FE * 100000L;

public CreativeGeneratorTile(BlockPos pos, BlockState state) {
Expand Down Expand Up @@ -51,4 +52,15 @@ public Component getDisplayName() {
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
return new CreativeGeneratorMenu(id, player, getBlockPos());
}

@Override
public void fromClientTag(CompoundTag tag) {
load(tag);
}

@Override
public CompoundTag toClientTag(CompoundTag tag) {
saveAdditional(tag);
return tag;
}
}
Loading

0 comments on commit 65e8ca6

Please sign in to comment.