mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-19 09:28:14 +01:00
Ask First
- Fixed Arms and Ejectors sending their placement configuration too early
This commit is contained in:
parent
7ea13cd6b1
commit
caa498875c
6 changed files with 85 additions and 16 deletions
|
@ -1,6 +1,9 @@
|
|||
package com.simibubi.create.content.logistics.block.depot;
|
||||
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
|
@ -10,9 +13,8 @@ import net.minecraft.world.item.context.UseOnContext;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
@EventBusSubscriber
|
||||
public class EjectorItem extends BlockItem {
|
||||
|
@ -36,11 +38,12 @@ public class EjectorItem extends BlockItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateCustomBlockEntityTag(BlockPos pos, Level world, Player p_195943_3_, ItemStack p_195943_4_,
|
||||
protected boolean updateCustomBlockEntityTag(BlockPos pos, Level world, Player player, ItemStack p_195943_4_,
|
||||
BlockState p_195943_5_) {
|
||||
if (world.isClientSide)
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> EjectorTargetHandler.flushSettings(pos));
|
||||
return super.updateCustomBlockEntityTag(pos, world, p_195943_3_, p_195943_4_, p_195943_5_);
|
||||
if (!world.isClientSide && player instanceof ServerPlayer sp)
|
||||
AllPackets.channel.send(PacketDistributor.PLAYER.with(() -> sp),
|
||||
new EjectorPlacementPacket.ClientBoundRequest(pos));
|
||||
return super.updateCustomBlockEntityTag(pos, world, player, p_195943_4_, p_195943_5_);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,8 @@ import net.minecraft.server.level.ServerPlayer;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.network.NetworkEvent.Context;
|
||||
|
||||
public class EjectorPlacementPacket extends SimplePacketBase {
|
||||
|
@ -65,4 +67,32 @@ public class EjectorPlacementPacket extends SimplePacketBase {
|
|||
|
||||
}
|
||||
|
||||
public static class ClientBoundRequest extends SimplePacketBase {
|
||||
|
||||
BlockPos pos;
|
||||
|
||||
public ClientBoundRequest(BlockPos pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public ClientBoundRequest(FriendlyByteBuf buffer) {
|
||||
this.pos = buffer.readBlockPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
buffer.writeBlockPos(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> EjectorTargetHandler.flushSettings(pos)));
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.simibubi.create.content.logistics.block.mechanicalArm;
|
||||
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
|
@ -9,9 +12,8 @@ import net.minecraft.world.item.context.UseOnContext;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
@EventBusSubscriber
|
||||
public class ArmItem extends BlockItem {
|
||||
|
@ -30,16 +32,16 @@ public class ArmItem extends BlockItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateCustomBlockEntityTag(BlockPos pos, Level world, Player p_195943_3_, ItemStack p_195943_4_,
|
||||
protected boolean updateCustomBlockEntityTag(BlockPos pos, Level world, Player player, ItemStack p_195943_4_,
|
||||
BlockState p_195943_5_) {
|
||||
if (world.isClientSide)
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ArmInteractionPointHandler.flushSettings(pos));
|
||||
return super.updateCustomBlockEntityTag(pos, world, p_195943_3_, p_195943_4_, p_195943_5_);
|
||||
if (!world.isClientSide && player instanceof ServerPlayer sp)
|
||||
AllPackets.channel.send(PacketDistributor.PLAYER.with(() -> sp),
|
||||
new ArmPlacementPacket.ClientBoundRequest(pos));
|
||||
return super.updateCustomBlockEntityTag(pos, world, player, p_195943_4_, p_195943_5_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAttackBlock(BlockState state, Level world, BlockPos pos,
|
||||
Player p_195938_4_) {
|
||||
public boolean canAttackBlock(BlockState state, Level world, BlockPos pos, Player p_195938_4_) {
|
||||
return !ArmInteractionPoint.isInteractable(world, pos, state);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ import net.minecraft.network.FriendlyByteBuf;
|
|||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.network.NetworkEvent.Context;
|
||||
|
||||
public class ArmPlacementPacket extends SimplePacketBase {
|
||||
|
@ -67,4 +69,32 @@ public class ArmPlacementPacket extends SimplePacketBase {
|
|||
|
||||
}
|
||||
|
||||
public static class ClientBoundRequest extends SimplePacketBase {
|
||||
|
||||
BlockPos pos;
|
||||
|
||||
public ClientBoundRequest(BlockPos pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public ClientBoundRequest(FriendlyByteBuf buffer) {
|
||||
this.pos = buffer.readBlockPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
buffer.writeBlockPos(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> ArmInteractionPointHandler.flushSettings(pos)));
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class ArmTileEntity extends KineticTileEntity implements ITransformableTE
|
|||
super(typeIn, pos, state);
|
||||
inputs = new ArrayList<>();
|
||||
outputs = new ArrayList<>();
|
||||
interactionPointTag = new ListTag();
|
||||
interactionPointTag = null;
|
||||
heldItem = ItemStack.EMPTY;
|
||||
phase = Phase.SEARCH_INPUTS;
|
||||
previousTarget = ArmAngleTarget.NO_TARGET;
|
||||
|
@ -480,7 +480,7 @@ public class ArmTileEntity extends KineticTileEntity implements ITransformableTE
|
|||
}
|
||||
|
||||
public void writeInteractionPoints(CompoundTag compound) {
|
||||
if (updateInteractionPoints) {
|
||||
if (updateInteractionPoints && interactionPointTag != null) {
|
||||
compound.put("InteractionPoints", interactionPointTag);
|
||||
} else {
|
||||
ListTag pointsNBT = new ListTag();
|
||||
|
|
|
@ -184,6 +184,10 @@ public enum AllPackets {
|
|||
S_TRAIN_PROMPT(TrainPromptPacket.class, TrainPromptPacket::new, PLAY_TO_CLIENT),
|
||||
CONTRAPTION_RELOCATION(ContraptionRelocationPacket.class, ContraptionRelocationPacket::new, PLAY_TO_CLIENT),
|
||||
TRACK_GRAPH_ROLL_CALL(TrackGraphRollCallPacket.class, TrackGraphRollCallPacket::new, PLAY_TO_CLIENT),
|
||||
S_PLACE_EJECTOR(ArmPlacementPacket.ClientBoundRequest.class, ArmPlacementPacket.ClientBoundRequest::new,
|
||||
PLAY_TO_CLIENT),
|
||||
S_PLACE_ARM(EjectorPlacementPacket.ClientBoundRequest.class, EjectorPlacementPacket.ClientBoundRequest::new,
|
||||
PLAY_TO_CLIENT),
|
||||
|
||||
;
|
||||
|
||||
|
|
Loading…
Reference in a new issue