mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-02-13 13:55:01 +01:00
Simplify packet handling
- SimplePacketBase#handle now accepts Context instead of Supplier<Context> - SimplePacketBase#handle now returns boolean, which, if true, calls Context#setPacketHandled(true)
This commit is contained in:
parent
f9c2cdb5f7
commit
bc0f349840
68 changed files with 569 additions and 785 deletions
|
@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.actors.controls;
|
|||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
|
||||
|
@ -40,35 +39,32 @@ public class ContraptionDisableActorPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityID);
|
||||
if (!(entityByID instanceof AbstractContraptionEntity ace))
|
||||
return;
|
||||
|
||||
Contraption contraption = ace.getContraption();
|
||||
List<ItemStack> disabledActors = contraption.getDisabledActors();
|
||||
if (filter.isEmpty())
|
||||
disabledActors.clear();
|
||||
|
||||
if (!enable) {
|
||||
disabledActors.add(filter);
|
||||
contraption.setActorsActive(filter, false);
|
||||
return;
|
||||
}
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityID);
|
||||
if (!(entityByID instanceof AbstractContraptionEntity ace))
|
||||
return;
|
||||
|
||||
Contraption contraption = ace.getContraption();
|
||||
List<ItemStack> disabledActors = contraption.getDisabledActors();
|
||||
if (filter.isEmpty())
|
||||
disabledActors.clear();
|
||||
|
||||
if (!enable) {
|
||||
disabledActors.add(filter);
|
||||
contraption.setActorsActive(filter, false);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Iterator<ItemStack> iterator = disabledActors.iterator(); iterator.hasNext();) {
|
||||
ItemStack next = iterator.next();
|
||||
if (ContraptionControlsMovement.isSameFilter(next, filter) || next.isEmpty())
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
contraption.setActorsActive(filter, true);
|
||||
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
for (Iterator<ItemStack> iterator = disabledActors.iterator(); iterator.hasNext();) {
|
||||
ItemStack next = iterator.next();
|
||||
if (ContraptionControlsMovement.isSameFilter(next, filter) || next.isEmpty())
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
contraption.setActorsActive(filter, true);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
@ -38,12 +36,10 @@ public class ContraptionBlockChangedPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> AbstractContraptionEntity.handleBlockChangedPacket(this)));
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> AbstractContraptionEntity.handleBlockChangedPacket(this)));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -31,12 +29,10 @@ public class ContraptionDisassemblyPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> AbstractContraptionEntity.handleDisassemblyPacket(this)));
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> AbstractContraptionEntity.handleDisassemblyPacket(this)));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -27,12 +25,10 @@ public class ContraptionRelocationPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> OrientedContraptionEntity.handleRelocationPacket(this)));
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT,
|
||||
() -> () -> OrientedContraptionEntity.handleRelocationPacket(this)));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -41,10 +39,10 @@ public class ContraptionStallPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(
|
||||
() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> AbstractContraptionEntity.handleStallPacket(this)));
|
||||
context.get().setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(
|
||||
() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> AbstractContraptionEntity.handleStallPacket(this)));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void writeAll(FriendlyByteBuf buffer, double... doubles) {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.logistics.trains.entity.CarriageContraptionEntity;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -36,10 +34,9 @@ public class TrainCollisionPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer player = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
Level level = player.level;
|
||||
|
||||
Entity entity = level.getEntity(contraptionEntityId);
|
||||
|
@ -50,7 +47,7 @@ public class TrainCollisionPacket extends SimplePacketBase {
|
|||
player.level.playSound(player, entity.blockPosition(), SoundEvents.PLAYER_ATTACK_CRIT, SoundSource.NEUTRAL,
|
||||
1, .75f);
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.el
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
|
@ -47,21 +46,18 @@ public class ElevatorFloorListPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityId);
|
||||
if (!(entityByID instanceof AbstractContraptionEntity ace))
|
||||
return;
|
||||
if (!(ace.getContraption()instanceof ElevatorContraption ec))
|
||||
return;
|
||||
|
||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityId);
|
||||
if (!(entityByID instanceof AbstractContraptionEntity ace))
|
||||
return;
|
||||
if (!(ace.getContraption()instanceof ElevatorContraption ec))
|
||||
return;
|
||||
|
||||
ec.namesList = floorsList;
|
||||
ec.syncControlDisplays();
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
ec.namesList = floorsList;
|
||||
ec.syncControlDisplays();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class RequestFloorList extends SimplePacketBase {
|
||||
|
@ -82,10 +78,9 @@ public class ElevatorFloorListPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer sender = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
Entity entityByID = sender.getLevel()
|
||||
.getEntity(entityId);
|
||||
if (!(entityByID instanceof AbstractContraptionEntity ace))
|
||||
|
@ -95,7 +90,7 @@ public class ElevatorFloorListPacket extends SimplePacketBase {
|
|||
AllPackets.getChannel().send(PacketDistributor.PLAYER.with(() -> sender),
|
||||
new ElevatorFloorListPacket(ace, ec.namesList));
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.elevator;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -36,10 +34,9 @@ public class ElevatorTargetFloorPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer sender = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
Entity entityByID = sender.getLevel()
|
||||
.getEntity(entityId);
|
||||
if (!(entityByID instanceof AbstractContraptionEntity ace))
|
||||
|
@ -69,7 +66,7 @@ public class ElevatorTargetFloorPacket extends SimplePacketBase {
|
|||
elevatorColumn.target(targetY);
|
||||
elevatorColumn.markDirty();
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.gantry;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -35,12 +33,10 @@ public class GantryContraptionUpdatePacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(
|
||||
() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> GantryContraptionEntity.handlePacket(this)));
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(
|
||||
() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> GantryContraptionEntity.handlePacket(this)));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.glue;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -9,7 +7,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.network.NetworkEvent.Context;
|
||||
|
||||
|
@ -31,21 +28,22 @@ public class GlueEffectPacket extends SimplePacketBase {
|
|||
fullBlock = buffer.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
buffer.writeBlockPos(pos);
|
||||
buffer.writeByte(direction.get3DDataValue());
|
||||
buffer.writeBoolean(fullBlock);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
@Override
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (!mc.player.blockPosition().closerThan(pos, 100))
|
||||
return;
|
||||
SuperGlueItem.spawnParticles(mc.level, pos, direction, fullBlock);
|
||||
}));
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.glue;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllSoundEvents;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -33,10 +31,9 @@ public class SuperGlueRemovalPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer player = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
Entity entity = player.level.getEntity(entityId);
|
||||
if (!(entity instanceof SuperGlueEntity superGlue))
|
||||
return;
|
||||
|
@ -47,7 +44,7 @@ public class SuperGlueRemovalPacket extends SimplePacketBase {
|
|||
superGlue.spawnParticles();
|
||||
entity.discard();
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.glue;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.advancement.AllAdvancements;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -36,10 +35,9 @@ public class SuperGlueSelectionPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer player = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
|
||||
double range = player.getAttribute(ForgeMod.REACH_DISTANCE.get())
|
||||
.getValue() + 2;
|
||||
|
@ -64,7 +62,7 @@ public class SuperGlueSelectionPacket extends SimplePacketBase {
|
|||
|
||||
AllAdvancements.SUPER_GLUE.awardTo(player);
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.in
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -55,10 +54,9 @@ public class ControlsInputPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer player = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
Level world = player.getCommandSenderWorld();
|
||||
UUID uniqueID = player.getUUID();
|
||||
|
||||
|
@ -77,7 +75,7 @@ public class ControlsInputPacket extends SimplePacketBase {
|
|||
.closerThan(player.position(), 16))
|
||||
ControlsServerHandler.receivePressed(world, ace, controlsPos, uniqueID, activatedButtons, press);
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.interaction.controls;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -17,11 +15,9 @@ public class ControlsStopControllingPacket extends SimplePacketBase {
|
|||
public void write(FriendlyByteBuf buffer) {}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(ControlsHandler::stopControlling);
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(ControlsHandler::stopControlling);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.interaction.controls;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.logistics.trains.entity.Train;
|
||||
|
@ -38,10 +37,9 @@ public class HonkPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context c = context.get();
|
||||
c.enqueueWork(() -> {
|
||||
ServerPlayer sender = c.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
boolean clientSide = sender == null;
|
||||
Train train = Create.RAILWAYS.sided(clientSide ? null : sender.level).trains.get(trainId);
|
||||
if (train == null)
|
||||
|
@ -58,7 +56,7 @@ public class HonkPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
});
|
||||
c.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class Serverbound extends HonkPacket {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.interaction.controls;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.logistics.trains.entity.Train;
|
||||
|
@ -47,10 +46,9 @@ public class TrainHUDUpdatePacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context c = context.get();
|
||||
c.enqueueWork(() -> {
|
||||
ServerPlayer sender = c.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
boolean clientSide = sender == null;
|
||||
Train train = Create.RAILWAYS.sided(clientSide ? null : sender.level).trains.get(trainId);
|
||||
if (train == null)
|
||||
|
@ -62,9 +60,8 @@ public class TrainHUDUpdatePacket extends SimplePacketBase {
|
|||
train.speed = speed;
|
||||
train.fuelTicks = fuelTicks;
|
||||
}
|
||||
|
||||
});
|
||||
c.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class Serverbound extends TrainHUDUpdatePacket {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.sync;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -40,26 +38,23 @@ public class ClientMotionPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.get()
|
||||
.getSender();
|
||||
if (sender == null)
|
||||
return;
|
||||
sender.setDeltaMovement(motion);
|
||||
sender.setOnGround(onGround);
|
||||
if (onGround) {
|
||||
sender.causeFallDamage(sender.fallDistance, 1, DamageSource.FALL);
|
||||
sender.fallDistance = 0;
|
||||
sender.connection.aboveGroundTickCount = 0;
|
||||
sender.connection.aboveGroundVehicleTickCount = 0;
|
||||
}
|
||||
AllPackets.getChannel().send(PacketDistributor.TRACKING_ENTITY.with(() -> sender),
|
||||
new LimbSwingUpdatePacket(sender.getId(), sender.position(), limbSwing));
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
if (sender == null)
|
||||
return;
|
||||
sender.setDeltaMovement(motion);
|
||||
sender.setOnGround(onGround);
|
||||
if (onGround) {
|
||||
sender.causeFallDamage(sender.fallDistance, 1, DamageSource.FALL);
|
||||
sender.fallDistance = 0;
|
||||
sender.connection.aboveGroundTickCount = 0;
|
||||
sender.connection.aboveGroundVehicleTickCount = 0;
|
||||
}
|
||||
AllPackets.getChannel().send(PacketDistributor.TRACKING_ENTITY.with(() -> sender),
|
||||
new LimbSwingUpdatePacket(sender.getId(), sender.position(), limbSwing));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.sync;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -38,16 +36,14 @@ public class ContraptionFluidPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityId);
|
||||
if (!(entityByID instanceof AbstractContraptionEntity))
|
||||
return;
|
||||
AbstractContraptionEntity contraptionEntity = (AbstractContraptionEntity) entityByID;
|
||||
contraptionEntity.getContraption().handleContraptionFluidPacket(localPos, containedFluid);
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityId);
|
||||
if (!(entityByID instanceof AbstractContraptionEntity))
|
||||
return;
|
||||
AbstractContraptionEntity contraptionEntity = (AbstractContraptionEntity) entityByID;
|
||||
contraptionEntity.getContraption().handleContraptionFluidPacket(localPos, containedFluid);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.sync;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -46,9 +44,9 @@ public class ContraptionInteractionPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayer sender = context.get().getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
if (sender == null)
|
||||
return;
|
||||
Entity entityByID = sender.getLevel().getEntity(target);
|
||||
|
@ -66,7 +64,7 @@ public class ContraptionInteractionPacket extends SimplePacketBase {
|
|||
if (contraptionEntity.handlePlayerInteraction(sender, localPos, face, interactionHand))
|
||||
sender.swing(interactionHand, true);
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.simibubi.create.content.contraptions.components.structureMovement.sy
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -52,29 +51,27 @@ public class ContraptionSeatMappingPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityID);
|
||||
if (!(entityByID instanceof AbstractContraptionEntity))
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityID);
|
||||
if (!(entityByID instanceof AbstractContraptionEntity))
|
||||
return;
|
||||
AbstractContraptionEntity contraptionEntity = (AbstractContraptionEntity) entityByID;
|
||||
|
||||
if (dismountedID != -1) {
|
||||
Entity dismountedByID = Minecraft.getInstance().level.getEntity(dismountedID);
|
||||
if (Minecraft.getInstance().player != dismountedByID)
|
||||
return;
|
||||
AbstractContraptionEntity contraptionEntity = (AbstractContraptionEntity) entityByID;
|
||||
|
||||
if (dismountedID != -1) {
|
||||
Entity dismountedByID = Minecraft.getInstance().level.getEntity(dismountedID);
|
||||
if (Minecraft.getInstance().player != dismountedByID)
|
||||
return;
|
||||
Vec3 transformedVector = contraptionEntity.getPassengerPosition(dismountedByID, 1);
|
||||
if (transformedVector != null)
|
||||
dismountedByID.getPersistentData()
|
||||
.put("ContraptionDismountLocation", VecHelper.writeNBT(transformedVector));
|
||||
}
|
||||
|
||||
contraptionEntity.getContraption()
|
||||
.setSeatMapping(mapping);
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
Vec3 transformedVector = contraptionEntity.getPassengerPosition(dismountedByID, 1);
|
||||
if (transformedVector != null)
|
||||
dismountedByID.getPersistentData()
|
||||
.put("ContraptionDismountLocation", VecHelper.writeNBT(transformedVector));
|
||||
}
|
||||
|
||||
contraptionEntity.getContraption()
|
||||
.setSeatMapping(mapping);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.sync;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -40,23 +38,21 @@ public class LimbSwingUpdatePacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ClientLevel world = Minecraft.getInstance().level;
|
||||
if (world == null)
|
||||
return;
|
||||
Entity entity = world.getEntity(entityId);
|
||||
if (entity == null)
|
||||
return;
|
||||
CompoundTag data = entity.getPersistentData();
|
||||
data.putInt("LastOverrideLimbSwingUpdate", 0);
|
||||
data.putFloat("OverrideLimbSwing", limbSwing);
|
||||
entity.lerpTo(position.x, position.y, position.z, entity.getYRot(),
|
||||
entity.getXRot(), 2, false);
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ClientLevel world = Minecraft.getInstance().level;
|
||||
if (world == null)
|
||||
return;
|
||||
Entity entity = world.getEntity(entityId);
|
||||
if (entity == null)
|
||||
return;
|
||||
CompoundTag data = entity.getPersistentData();
|
||||
data.putInt("LastOverrideLimbSwingUpdate", 0);
|
||||
data.putFloat("OverrideLimbSwing", limbSwing);
|
||||
entity.lerpTo(position.x, position.y, position.z, entity.getYRot(),
|
||||
entity.getXRot(), 2, false);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.train;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -30,16 +28,13 @@ public class CouplingCreationPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.get()
|
||||
.getSender();
|
||||
if (sender != null)
|
||||
CouplingHandler.tryToCoupleCarts(sender, sender.level, id1, id2);
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
if (sender != null)
|
||||
CouplingHandler.tryToCoupleCarts(sender, sender.level, id1, id2);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.train.capability;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -37,11 +35,9 @@ public class MinecartControllerUpdatePacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::handleCL));
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::handleCL));
|
||||
return true;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.contraptions.fluids.actors;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.contraptions.fluids.FluidFX;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -29,21 +27,21 @@ public class FluidSplashPacket extends SimplePacketBase {
|
|||
fluid = buffer.readFluidStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
buffer.writeBlockPos(pos);
|
||||
buffer.writeFluidStack(fluid);
|
||||
}
|
||||
|
||||
public void handle(Supplier<Context> ctx) {
|
||||
ctx.get()
|
||||
.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
if (Minecraft.getInstance().player.position()
|
||||
.distanceTo(new Vec3(pos.getX(), pos.getY(), pos.getZ())) > 100)
|
||||
return;
|
||||
FluidFX.splash(pos, fluid);
|
||||
}));
|
||||
ctx.get()
|
||||
.setPacketHandled(true);
|
||||
@Override
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
if (Minecraft.getInstance().player.position()
|
||||
.distanceTo(new Vec3(pos.getX(), pos.getY(), pos.getZ())) > 100)
|
||||
return;
|
||||
FluidFX.splash(pos, fluid);
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.jozufozu.flywheel.core.PartialModel;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.simibubi.create.AllPartialModels;
|
||||
import com.simibubi.create.content.contraptions.base.KineticBlockEntity;
|
||||
import com.simibubi.create.content.contraptions.relays.encased.ShaftRenderer;
|
||||
import com.simibubi.create.content.contraptions.relays.gauge.GaugeBlock.Type;
|
||||
import com.simibubi.create.foundation.render.CachedBufferer;
|
||||
|
@ -19,7 +18,7 @@ import net.minecraft.core.Direction;
|
|||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class GaugeRenderer extends ShaftRenderer {
|
||||
public class GaugeRenderer extends ShaftRenderer<GaugeBlockEntity> {
|
||||
|
||||
protected GaugeBlock.Type type;
|
||||
|
||||
|
@ -37,7 +36,7 @@ public class GaugeRenderer extends ShaftRenderer {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void renderSafe(KineticBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer,
|
||||
protected void renderSafe(GaugeBlockEntity be, float partialTicks, PoseStack ms, MultiBufferSource buffer,
|
||||
int light, int overlay) {
|
||||
if (Backend.canUseInstancing(be.getLevel())) return;
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.curiosities.armor;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -137,14 +135,14 @@ public final class NetheriteDivingHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
Entity entity = Minecraft.getInstance().level.getEntity(entityId);
|
||||
if (entity != null) {
|
||||
entity.getPersistentData().putBoolean(FIRE_IMMUNE_KEY, fireImmune);
|
||||
}
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package com.simibubi.create.content.curiosities.bell;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkEvent.Context;
|
||||
|
||||
public class SoulPulseEffectPacket extends SimplePacketBase {
|
||||
|
||||
|
@ -35,11 +33,11 @@ public class SoulPulseEffectPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<NetworkEvent.Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
CreateClient.SOUL_PULSE_EFFECT_HANDLER.addPulse(new SoulPulseEffect(pos, distance, canOverlap));
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.curiosities.symmetry;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.curiosities.symmetry.mirror.SymmetryMirror;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -33,9 +31,9 @@ public class ConfigureSymmetryWandPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayer player = context.get().getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -44,7 +42,7 @@ public class ConfigureSymmetryWandPacket extends SimplePacketBase {
|
|||
SymmetryWandItem.configureSettings(stack, mirror);
|
||||
}
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.simibubi.create.content.curiosities.symmetry;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -43,14 +42,14 @@ public class SymmetryEffectPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
if (Minecraft.getInstance().player.position().distanceTo(Vec3.atLowerCornerOf(mirror)) > 100)
|
||||
return;
|
||||
for (BlockPos to : positions)
|
||||
SymmetryHandler.drawEffect(mirror, to);
|
||||
}));
|
||||
ctx.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.curiosities.toolbox;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -35,10 +33,9 @@ public class ToolboxDisposeAllPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer player = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
Level world = player.level;
|
||||
BlockEntity blockEntity = world.getBlockEntity(toolboxPos);
|
||||
|
||||
|
@ -73,9 +70,8 @@ public class ToolboxDisposeAllPacket extends SimplePacketBase {
|
|||
|
||||
if (sendData.booleanValue())
|
||||
ToolboxHandler.syncData(player);
|
||||
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.curiosities.toolbox;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
@ -44,10 +42,9 @@ public class ToolboxEquipPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer player = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
Level world = player.level;
|
||||
|
||||
if (toolboxPos == null) {
|
||||
|
@ -102,7 +99,7 @@ public class ToolboxEquipPacket extends SimplePacketBase {
|
|||
toolboxBlockEntity.connectPlayer(slot, player, hotbarSlot);
|
||||
ToolboxHandler.syncData(player);
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.curiosities.tools;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -27,23 +25,20 @@ public class BlueprintAssignCompleteRecipePacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer player = context.get()
|
||||
.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
if (player.containerMenu instanceof BlueprintMenu) {
|
||||
BlueprintMenu c = (BlueprintMenu) player.containerMenu;
|
||||
player.getLevel()
|
||||
.getRecipeManager()
|
||||
.byKey(recipeID)
|
||||
.ifPresent(r -> BlueprintItem.assignCompleteRecipe(c.ghostInventory, r));
|
||||
}
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
if (player.containerMenu instanceof BlueprintMenu) {
|
||||
BlueprintMenu c = (BlueprintMenu) player.containerMenu;
|
||||
player.getLevel()
|
||||
.getRecipeManager()
|
||||
.byKey(recipeID)
|
||||
.ifPresent(r -> BlueprintItem.assignCompleteRecipe(c.ghostInventory, r));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.curiosities.tools;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -53,33 +51,30 @@ public class ExtendoGripInteractionPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.get()
|
||||
.getSender();
|
||||
if (sender == null)
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
if (sender == null)
|
||||
return;
|
||||
Entity entityByID = sender.getLevel()
|
||||
.getEntity(target);
|
||||
if (entityByID != null && ExtendoGripItem.isHoldingExtendoGrip(sender)) {
|
||||
double d = sender.getAttribute(ForgeMod.REACH_DISTANCE.get())
|
||||
.getValue();
|
||||
if (!sender.hasLineOfSight(entityByID))
|
||||
d -= 3;
|
||||
d *= d;
|
||||
if (sender.distanceToSqr(entityByID) > d)
|
||||
return;
|
||||
Entity entityByID = sender.getLevel()
|
||||
.getEntity(target);
|
||||
if (entityByID != null && ExtendoGripItem.isHoldingExtendoGrip(sender)) {
|
||||
double d = sender.getAttribute(ForgeMod.REACH_DISTANCE.get())
|
||||
.getValue();
|
||||
if (!sender.hasLineOfSight(entityByID))
|
||||
d -= 3;
|
||||
d *= d;
|
||||
if (sender.distanceToSqr(entityByID) > d)
|
||||
return;
|
||||
if (interactionHand == null)
|
||||
sender.attack(entityByID);
|
||||
else if (specificPoint == null)
|
||||
sender.interactOn(entityByID, interactionHand);
|
||||
else
|
||||
entityByID.interactAt(sender, specificPoint, interactionHand);
|
||||
}
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
if (interactionHand == null)
|
||||
sender.attack(entityByID);
|
||||
else if (specificPoint == null)
|
||||
sender.interactOn(entityByID, interactionHand);
|
||||
else
|
||||
entityByID.interactAt(sender, specificPoint, interactionHand);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -148,11 +148,11 @@ public class PotatoProjectileTypeManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
fromBuffer(buffer);
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.curiosities.zapper;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -32,9 +30,9 @@ public abstract class ConfigureZapperPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayer player = context.get().getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -43,7 +41,7 @@ public abstract class ConfigureZapperPacket extends SimplePacketBase {
|
|||
configureZapper(stack);
|
||||
}
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract void configureZapper(ItemStack stack);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.curiosities.zapper;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -53,26 +51,24 @@ public abstract class ShootGadgetPacket extends SimplePacketBase {
|
|||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public final void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
Entity renderViewEntity = Minecraft.getInstance()
|
||||
.getCameraEntity();
|
||||
if (renderViewEntity == null)
|
||||
return;
|
||||
if (renderViewEntity.position()
|
||||
.distanceTo(location) > 100)
|
||||
return;
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
Entity renderViewEntity = Minecraft.getInstance()
|
||||
.getCameraEntity();
|
||||
if (renderViewEntity == null)
|
||||
return;
|
||||
if (renderViewEntity.position()
|
||||
.distanceTo(location) > 100)
|
||||
return;
|
||||
|
||||
ShootableGadgetRenderHandler handler = getHandler();
|
||||
handleAdditional();
|
||||
if (self)
|
||||
handler.shoot(hand, location);
|
||||
else
|
||||
handler.playSound(hand, location);
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
ShootableGadgetRenderHandler handler = getHandler();
|
||||
handleAdditional();
|
||||
if (self)
|
||||
handler.shoot(hand, location);
|
||||
else
|
||||
handler.playSound(hand, location);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.logistics.block.depot;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
@ -29,23 +27,19 @@ public class EjectorElytraPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer player = context.get()
|
||||
.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
Level world = player.level;
|
||||
if (world == null || !world.isLoaded(pos))
|
||||
return;
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof EjectorBlockEntity)
|
||||
((EjectorBlockEntity) blockEntity).deployElytra(player);
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
Level world = player.level;
|
||||
if (world == null || !world.isLoaded(pos))
|
||||
return;
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof EjectorBlockEntity)
|
||||
((EjectorBlockEntity) blockEntity).deployElytra(player);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.logistics.block.depot;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -43,26 +41,22 @@ public class EjectorPlacementPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer player = context.get()
|
||||
.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
Level world = player.level;
|
||||
if (world == null || !world.isLoaded(pos))
|
||||
return;
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if (blockEntity instanceof EjectorBlockEntity)
|
||||
((EjectorBlockEntity) blockEntity).setTarget(h, v);
|
||||
if (AllBlocks.WEIGHTED_EJECTOR.has(state))
|
||||
world.setBlockAndUpdate(pos, state.setValue(EjectorBlock.HORIZONTAL_FACING, facing));
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
Level world = player.level;
|
||||
if (world == null || !world.isLoaded(pos))
|
||||
return;
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
BlockState state = world.getBlockState(pos);
|
||||
if (blockEntity instanceof EjectorBlockEntity)
|
||||
((EjectorBlockEntity) blockEntity).setTarget(h, v);
|
||||
if (AllBlocks.WEIGHTED_EJECTOR.has(state))
|
||||
world.setBlockAndUpdate(pos, state.setValue(EjectorBlock.HORIZONTAL_FACING, facing));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.content.logistics.block.mechanicalArm;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -45,26 +44,22 @@ public class ArmPlacementPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer player = context.get()
|
||||
.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
Level world = player.level;
|
||||
if (world == null || !world.isLoaded(pos))
|
||||
return;
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (!(blockEntity instanceof ArmBlockEntity))
|
||||
return;
|
||||
|
||||
ArmBlockEntity arm = (ArmBlockEntity) blockEntity;
|
||||
arm.interactionPointTag = receivedTag;
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
Level world = player.level;
|
||||
if (world == null || !world.isLoaded(pos))
|
||||
return;
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (!(blockEntity instanceof ArmBlockEntity))
|
||||
return;
|
||||
|
||||
ArmBlockEntity arm = (ArmBlockEntity) blockEntity;
|
||||
arm.interactionPointTag = receivedTag;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.logistics.item;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -41,9 +39,9 @@ public abstract class LinkedControllerPacketBase extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayer player = context.get().getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
|
@ -62,8 +60,7 @@ public abstract class LinkedControllerPacketBase extends SimplePacketBase {
|
|||
handleItem(player, controller);
|
||||
}
|
||||
});
|
||||
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void handleItem(ServerPlayer player, ItemStack heldItem);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.logistics.item.filter;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.logistics.item.filter.AttributeFilterMenu.WhitelistMode;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -40,9 +38,9 @@ public class FilterScreenPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayer player = context.get().getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
|
@ -77,7 +75,7 @@ public class FilterScreenPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.content.logistics.trains;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -15,11 +14,9 @@ public abstract class TrackGraphPacket extends SimplePacketBase {
|
|||
public boolean packetDeletesGraph;
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> handle(CreateClient.RAILWAYS, CreateClient.RAILWAYS.getOrCreateGraph(graphId, netId)));
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> handle(CreateClient.RAILWAYS, CreateClient.RAILWAYS.getOrCreateGraph(graphId, netId)));
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void handle(GlobalRailwayManager manager, TrackGraph graph);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.logistics.trains;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -26,19 +24,16 @@ public class TrackGraphRequestPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
for (TrackGraph trackGraph : Create.RAILWAYS.trackNetworks.values()) {
|
||||
if (trackGraph.netId == netId) {
|
||||
Create.RAILWAYS.sync.sendFullGraphTo(trackGraph, context.get()
|
||||
.getSender());
|
||||
break;
|
||||
}
|
||||
if (trackGraph.netId == netId) {
|
||||
Create.RAILWAYS.sync.sendFullGraphTo(trackGraph, context.getSender());
|
||||
break;
|
||||
}
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
|
@ -45,39 +44,35 @@ public class TrackGraphRollCallPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
GlobalRailwayManager manager = Create.RAILWAYS.sided(null);
|
||||
Set<UUID> unusedIds = new HashSet<>(manager.trackNetworks.keySet());
|
||||
List<Integer> failedIds = new ArrayList<>();
|
||||
Map<Integer, UUID> idByNetId = new HashMap<>();
|
||||
manager.trackNetworks.forEach((uuid, g) -> idByNetId.put(g.netId, uuid));
|
||||
|
||||
GlobalRailwayManager manager = Create.RAILWAYS.sided(null);
|
||||
Set<UUID> unusedIds = new HashSet<>(manager.trackNetworks.keySet());
|
||||
List<Integer> failedIds = new ArrayList<>();
|
||||
Map<Integer, UUID> idByNetId = new HashMap<>();
|
||||
manager.trackNetworks.forEach((uuid, g) -> idByNetId.put(g.netId, uuid));
|
||||
|
||||
for (int i = 0; i < ints.length; i += 2) {
|
||||
UUID uuid = idByNetId.get(ints[i]);
|
||||
if (uuid == null) {
|
||||
failedIds.add(ints[i]);
|
||||
continue;
|
||||
}
|
||||
unusedIds.remove(uuid);
|
||||
TrackGraph trackGraph = manager.trackNetworks.get(uuid);
|
||||
if (trackGraph.getChecksum() == ints[i + 1])
|
||||
continue;
|
||||
Create.LOGGER.warn("Track network: " + uuid.toString()
|
||||
.substring(0, 6) + " failed its checksum; Requesting refresh");
|
||||
for (int i = 0; i < ints.length; i += 2) {
|
||||
UUID uuid = idByNetId.get(ints[i]);
|
||||
if (uuid == null) {
|
||||
failedIds.add(ints[i]);
|
||||
continue;
|
||||
}
|
||||
unusedIds.remove(uuid);
|
||||
TrackGraph trackGraph = manager.trackNetworks.get(uuid);
|
||||
if (trackGraph.getChecksum() == ints[i + 1])
|
||||
continue;
|
||||
Create.LOGGER.warn("Track network: " + uuid.toString()
|
||||
.substring(0, 6) + " failed its checksum; Requesting refresh");
|
||||
failedIds.add(ints[i]);
|
||||
}
|
||||
|
||||
for (Integer failed : failedIds)
|
||||
AllPackets.getChannel().sendToServer(new TrackGraphRequestPacket(failed));
|
||||
for (UUID unused : unusedIds)
|
||||
manager.trackNetworks.remove(unused);
|
||||
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
for (Integer failed : failedIds)
|
||||
AllPackets.getChannel().sendToServer(new TrackGraphRequestPacket(failed));
|
||||
for (UUID unused : unusedIds)
|
||||
manager.trackNetworks.remove(unused);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.content.logistics.trains.IBogeyBlock;
|
||||
|
@ -99,17 +98,15 @@ public class TrainPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
Map<UUID, Train> trains = CreateClient.RAILWAYS.trains;
|
||||
if (add)
|
||||
trains.put(train.id, train);
|
||||
else
|
||||
trains.remove(trainId);
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
Map<UUID, Train> trains = CreateClient.RAILWAYS.trains;
|
||||
if (add)
|
||||
trains.put(train.id, train);
|
||||
else
|
||||
trains.remove(trainId);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.logistics.trains.entity;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.controls.TrainHUD;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -34,11 +32,9 @@ public class TrainPromptPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::apply));
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::apply));
|
||||
return true;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.content.logistics.trains.entity;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionRelocationPacket;
|
||||
|
@ -65,10 +64,9 @@ public class TrainRelocationPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer sender = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
Train train = Create.RAILWAYS.trains.get(trainId);
|
||||
Entity entity = sender.level.getEntity(entityId);
|
||||
|
||||
|
@ -109,9 +107,8 @@ public class TrainRelocationPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
Create.LOGGER.warn(messagePrefix + train.name.getString() + ": relocation failed server-side");
|
||||
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.simibubi.create.CreateClient;
|
||||
|
@ -51,26 +50,24 @@ public class SignalEdgeGroupPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
Map<UUID, SignalEdgeGroup> signalEdgeGroups = CreateClient.RAILWAYS.signalEdgeGroups;
|
||||
int i = 0;
|
||||
for (UUID id : ids) {
|
||||
if (!add) {
|
||||
signalEdgeGroups.remove(id);
|
||||
continue;
|
||||
}
|
||||
|
||||
SignalEdgeGroup group = new SignalEdgeGroup(id);
|
||||
signalEdgeGroups.put(id, group);
|
||||
if (colors.size() > i)
|
||||
group.color = colors.get(i);
|
||||
i++;
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
Map<UUID, SignalEdgeGroup> signalEdgeGroups = CreateClient.RAILWAYS.signalEdgeGroups;
|
||||
int i = 0;
|
||||
for (UUID id : ids) {
|
||||
if (!add) {
|
||||
signalEdgeGroups.remove(id);
|
||||
continue;
|
||||
}
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
|
||||
SignalEdgeGroup group = new SignalEdgeGroup(id);
|
||||
signalEdgeGroups.put(id, group);
|
||||
if (colors.size() > i)
|
||||
group.color = colors.get(i);
|
||||
i++;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.content.logistics.trains.management.edgePoint.station;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.logistics.trains.entity.Train;
|
||||
|
@ -43,10 +42,9 @@ public class TrainEditPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer sender = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
Level level = sender == null ? null : sender.level;
|
||||
Train train = Create.RAILWAYS.sided(level).trains.get(id);
|
||||
if (train == null)
|
||||
|
@ -57,7 +55,7 @@ public class TrainEditPacket extends SimplePacketBase {
|
|||
if (sender != null)
|
||||
AllPackets.getChannel().send(PacketDistributor.ALL.noArg(), new TrainEditReturnPacket(id, name, iconType));
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class TrainEditReturnPacket extends TrainEditPacket {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.logistics.trains.management.schedule;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -29,28 +27,25 @@ public class ScheduleEditPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.get()
|
||||
.getSender();
|
||||
ItemStack mainHandItem = sender.getMainHandItem();
|
||||
if (!AllItems.SCHEDULE.isIn(mainHandItem))
|
||||
return;
|
||||
|
||||
CompoundTag tag = mainHandItem.getOrCreateTag();
|
||||
if (schedule.entries.isEmpty()) {
|
||||
tag.remove("Schedule");
|
||||
if (tag.isEmpty())
|
||||
mainHandItem.setTag(null);
|
||||
} else
|
||||
tag.put("Schedule", schedule.write());
|
||||
|
||||
sender.getCooldowns()
|
||||
.addCooldown(mainHandItem.getItem(), 5);
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
ItemStack mainHandItem = sender.getMainHandItem();
|
||||
if (!AllItems.SCHEDULE.isIn(mainHandItem))
|
||||
return;
|
||||
|
||||
CompoundTag tag = mainHandItem.getOrCreateTag();
|
||||
if (schedule.entries.isEmpty()) {
|
||||
tag.remove("Schedule");
|
||||
if (tag.isEmpty())
|
||||
mainHandItem.setTag(null);
|
||||
} else
|
||||
tag.put("Schedule", schedule.write());
|
||||
|
||||
sender.getCooldowns()
|
||||
.addCooldown(mainHandItem.getItem(), 5);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.logistics.trains.track;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -34,10 +32,9 @@ public class PlaceExtendedCurvePacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer sender = ctx.getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer sender = context.getSender();
|
||||
ItemStack stack = sender.getItemInHand(mainHand ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND);
|
||||
if (!AllBlocks.TRACK.isIn(stack) || !stack.hasTag())
|
||||
return;
|
||||
|
@ -45,7 +42,7 @@ public class PlaceExtendedCurvePacket extends SimplePacketBase {
|
|||
tag.putBoolean("ExtendCurve", true);
|
||||
stack.setTag(tag);
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.schematics.packet;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.schematics.block.SchematicannonBlockEntity;
|
||||
import com.simibubi.create.content.schematics.block.SchematicannonBlockEntity.State;
|
||||
import com.simibubi.create.content.schematics.block.SchematicannonMenu;
|
||||
|
@ -29,14 +27,16 @@ public class ConfigureSchematicannonPacket extends SimplePacketBase {
|
|||
this(buffer.readEnum(Option.class), buffer.readBoolean());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
buffer.writeEnum(option);
|
||||
buffer.writeBoolean(set);
|
||||
}
|
||||
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayer player = context.get().getSender();
|
||||
@Override
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null || !(player.containerMenu instanceof SchematicannonMenu))
|
||||
return;
|
||||
|
||||
|
@ -73,7 +73,7 @@ public class ConfigureSchematicannonPacket extends SimplePacketBase {
|
|||
|
||||
be.sendUpdate = true;
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.schematics.packet;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
|
@ -36,17 +34,14 @@ public class InstantSchematicPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer player = context.get()
|
||||
.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
Create.SCHEMATIC_RECEIVER.handleInstantSchematic(player, name, player.level, origin, bounds);
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
Create.SCHEMATIC_RECEIVER.handleInstantSchematic(player, name, player.level, origin, bounds);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.schematics.packet;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.content.schematics.SchematicPrinter;
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -26,13 +24,15 @@ public class SchematicPlacePacket extends SimplePacketBase {
|
|||
stack = buffer.readItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
buffer.writeItem(stack);
|
||||
}
|
||||
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayer player = context.get().getSender();
|
||||
@Override
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class SchematicPlacePacket extends SimplePacketBase {
|
|||
});
|
||||
}
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.schematics.packet;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllItems;
|
||||
import com.simibubi.create.content.schematics.filtering.SchematicInstances;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -52,9 +50,9 @@ public class SchematicSyncPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
ServerPlayer player = context.get().getSender();
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
ItemStack stack = ItemStack.EMPTY;
|
||||
|
@ -73,7 +71,7 @@ public class SchematicSyncPacket extends SimplePacketBase {
|
|||
tag.putString("Mirror", mirror.name());
|
||||
SchematicInstances.clearHash(stack);
|
||||
});
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.content.schematics.packet;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.schematics.block.SchematicTableMenu;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -53,6 +51,7 @@ public class SchematicUploadPacket extends SimplePacketBase {
|
|||
data = buffer.readByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(FriendlyByteBuf buffer) {
|
||||
buffer.writeInt(code);
|
||||
buffer.writeUtf(schematic);
|
||||
|
@ -63,25 +62,23 @@ public class SchematicUploadPacket extends SimplePacketBase {
|
|||
buffer.writeByteArray(data);
|
||||
}
|
||||
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer player = context.get()
|
||||
.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
if (code == BEGIN) {
|
||||
BlockPos pos = ((SchematicTableMenu) player.containerMenu).contentHolder
|
||||
.getBlockPos();
|
||||
Create.SCHEMATIC_RECEIVER.handleNewUpload(player, schematic, size, pos);
|
||||
}
|
||||
if (code == WRITE)
|
||||
Create.SCHEMATIC_RECEIVER.handleWriteRequest(player, schematic, data);
|
||||
if (code == FINISH)
|
||||
Create.SCHEMATIC_RECEIVER.handleFinishedUpload(player, schematic);
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
@Override
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
if (code == BEGIN) {
|
||||
BlockPos pos = ((SchematicTableMenu) player.containerMenu).contentHolder
|
||||
.getBlockPos();
|
||||
Create.SCHEMATIC_RECEIVER.handleNewUpload(player, schematic, size, pos);
|
||||
}
|
||||
if (code == WRITE)
|
||||
Create.SCHEMATIC_RECEIVER.handleWriteRequest(player, schematic, data);
|
||||
if (code == FINISH)
|
||||
Create.SCHEMATIC_RECEIVER.handleFinishedUpload(player, schematic);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.foundation.command;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.AllSpecialTextures;
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -13,7 +11,7 @@ import net.minecraft.world.phys.shapes.Shapes;
|
|||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkEvent.Context;
|
||||
|
||||
public class HighlightPacket extends SimplePacketBase {
|
||||
|
||||
|
@ -33,14 +31,11 @@ public class HighlightPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get()
|
||||
.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
performHighlight(pos);
|
||||
}));
|
||||
|
||||
ctx.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
performHighlight(pos);
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
|
|
@ -33,7 +33,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
|
|||
import net.minecraftforge.common.ForgeConfig;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.network.NetworkEvent.Context;
|
||||
|
||||
public class SConfigureConfigPacket extends SimplePacketBase {
|
||||
|
||||
|
@ -59,24 +59,21 @@ public class SConfigureConfigPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get()
|
||||
.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
if (option.startsWith("SET")) {
|
||||
trySetConfig(option.substring(3), value);
|
||||
return;
|
||||
}
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
|
||||
if (option.startsWith("SET")) {
|
||||
trySetConfig(option.substring(3), value);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Actions.valueOf(option)
|
||||
.performAction(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOGGER.warn("Received ConfigureConfigPacket with invalid Option: " + option);
|
||||
}
|
||||
}));
|
||||
|
||||
ctx.get()
|
||||
.setPacketHandled(true);
|
||||
try {
|
||||
Actions.valueOf(option)
|
||||
.performAction(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOGGER.warn("Received ConfigureConfigPacket with invalid Option: " + option);
|
||||
}
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void trySetConfig(String option, String value) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.foundation.config.ui;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -38,10 +37,10 @@ public class CConfigureConfigPacket<T> extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<NetworkEvent.Context> context) {
|
||||
context.get().enqueueWork(() -> {
|
||||
public boolean handle(NetworkEvent.Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
try {
|
||||
ServerPlayer sender = context.get().getSender();
|
||||
ServerPlayer sender = context.getSender();
|
||||
if (sender == null || !sender.hasPermissions(2))
|
||||
return;
|
||||
|
||||
|
@ -60,8 +59,7 @@ public class CConfigureConfigPacket<T> extends SimplePacketBase {
|
|||
Create.LOGGER.warn("Unable to handle ConfigureConfig Packet. ", e);
|
||||
}
|
||||
});
|
||||
|
||||
context.get().setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public String serialize(T value) {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.foundation.gui.menu;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -18,19 +16,16 @@ public class ClearMenuPacket extends SimplePacketBase {
|
|||
public void write(FriendlyByteBuf buffer) {}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer player = context.get()
|
||||
.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
if (!(player.containerMenu instanceof IClearableMenu))
|
||||
return;
|
||||
((IClearableMenu) player.containerMenu).clearContents();
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
if (!(player.containerMenu instanceof IClearableMenu))
|
||||
return;
|
||||
((IClearableMenu) player.containerMenu).clearContents();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.foundation.gui.menu;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -31,22 +29,18 @@ public class GhostItemSubmitPacket extends SimplePacketBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer player = context.get()
|
||||
.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (player.containerMenu instanceof GhostItemMenu<?> menu) {
|
||||
menu.ghostInventory.setStackInSlot(slot, item);
|
||||
menu.getSlot(36 + slot).setChanged();
|
||||
}
|
||||
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
if (player.containerMenu instanceof GhostItemMenu<?> menu) {
|
||||
menu.ghostInventory.setStackInSlot(slot, item);
|
||||
menu.getSlot(36 + slot).setChanged();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -204,11 +204,11 @@ public enum AllPackets {
|
|||
public static final String NETWORK_VERSION_STR = String.valueOf(NETWORK_VERSION);
|
||||
private static SimpleChannel channel;
|
||||
|
||||
private LoadedPacket<?> packet;
|
||||
private PacketType<?> packetType;
|
||||
|
||||
<T extends SimplePacketBase> AllPackets(Class<T> type, Function<FriendlyByteBuf, T> factory,
|
||||
NetworkDirection direction) {
|
||||
packet = new LoadedPacket<>(type, factory, direction);
|
||||
packetType = new PacketType<>(type, factory, direction);
|
||||
}
|
||||
|
||||
public static void registerPackets() {
|
||||
|
@ -217,8 +217,9 @@ public enum AllPackets {
|
|||
.clientAcceptedVersions(NETWORK_VERSION_STR::equals)
|
||||
.networkProtocolVersion(() -> NETWORK_VERSION_STR)
|
||||
.simpleChannel();
|
||||
|
||||
for (AllPackets packet : values())
|
||||
packet.packet.register();
|
||||
packet.packetType.register();
|
||||
}
|
||||
|
||||
public static SimpleChannel getChannel() {
|
||||
|
@ -231,7 +232,7 @@ public enum AllPackets {
|
|||
message);
|
||||
}
|
||||
|
||||
private static class LoadedPacket<T extends SimplePacketBase> {
|
||||
private static class PacketType<T extends SimplePacketBase> {
|
||||
private static int index = 0;
|
||||
|
||||
private BiConsumer<T, FriendlyByteBuf> encoder;
|
||||
|
@ -240,10 +241,15 @@ public enum AllPackets {
|
|||
private Class<T> type;
|
||||
private NetworkDirection direction;
|
||||
|
||||
private LoadedPacket(Class<T> type, Function<FriendlyByteBuf, T> factory, NetworkDirection direction) {
|
||||
private PacketType(Class<T> type, Function<FriendlyByteBuf, T> factory, NetworkDirection direction) {
|
||||
encoder = T::write;
|
||||
decoder = factory;
|
||||
handler = T::handle;
|
||||
handler = (packet, contextSupplier) -> {
|
||||
Context context = contextSupplier.get();
|
||||
if (packet.handle(context)) {
|
||||
context.setPacketHandled(true);
|
||||
}
|
||||
};
|
||||
this.type = type;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.foundation.networking;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.blockEntity.SyncedBlockEntity;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
@ -32,30 +30,26 @@ public abstract class BlockEntityConfigurationPacket<BE extends SyncedBlockEntit
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
ServerPlayer player = context.get()
|
||||
.getSender();
|
||||
if (player == null)
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ServerPlayer player = context.getSender();
|
||||
if (player == null)
|
||||
return;
|
||||
Level world = player.level;
|
||||
if (world == null || !world.isLoaded(pos))
|
||||
return;
|
||||
if (!pos.closerThan(player.blockPosition(), maxRange()))
|
||||
return;
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof SyncedBlockEntity) {
|
||||
applySettings(player, (BE) blockEntity);
|
||||
if (!causeUpdate())
|
||||
return;
|
||||
Level world = player.level;
|
||||
if (world == null || !world.isLoaded(pos))
|
||||
return;
|
||||
if (!pos.closerThan(player.blockPosition(), maxRange()))
|
||||
return;
|
||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||
if (blockEntity instanceof SyncedBlockEntity) {
|
||||
applySettings(player, (BE) blockEntity);
|
||||
if (!causeUpdate())
|
||||
return;
|
||||
((SyncedBlockEntity) blockEntity).sendData();
|
||||
blockEntity.setChanged();
|
||||
}
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
|
||||
((SyncedBlockEntity) blockEntity).sendData();
|
||||
blockEntity.setChanged();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
protected int maxRange() {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.foundation.networking;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.blockEntity.SyncedBlockEntity;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -35,9 +33,8 @@ public abstract class BlockEntityDataPacket<BE extends SyncedBlockEntity> extend
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<NetworkEvent.Context> context) {
|
||||
NetworkEvent.Context ctx = context.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
public boolean handle(NetworkEvent.Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
ClientLevel world = Minecraft.getInstance().level;
|
||||
|
||||
if (world == null)
|
||||
|
@ -49,7 +46,7 @@ public abstract class BlockEntityDataPacket<BE extends SyncedBlockEntity> extend
|
|||
handlePacket((BE) blockEntity);
|
||||
}
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void writeData(FriendlyByteBuf buffer);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simibubi.create.foundation.networking;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -41,19 +40,17 @@ public interface ISyncPersistentData {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityId);
|
||||
CompoundTag data = entityByID.getPersistentData();
|
||||
new HashSet<>(data.getAllKeys()).forEach(data::remove);
|
||||
data.merge(readData);
|
||||
if (!(entityByID instanceof ISyncPersistentData))
|
||||
return;
|
||||
((ISyncPersistentData) entityByID).onPersistentDataUpdated();
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
Entity entityByID = Minecraft.getInstance().level.getEntity(entityId);
|
||||
CompoundTag data = entityByID.getPersistentData();
|
||||
new HashSet<>(data.getAllKeys()).forEach(data::remove);
|
||||
data.merge(readData);
|
||||
if (!(entityByID instanceof ISyncPersistentData))
|
||||
return;
|
||||
((ISyncPersistentData) entityByID).onPersistentDataUpdated();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.foundation.networking;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.events.CommonEvents;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -18,12 +16,11 @@ public class LeftClickPacket extends SimplePacketBase {
|
|||
public void write(FriendlyByteBuf buffer) {}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
Context ctx = context.get();
|
||||
if (ctx.getDirection() != NetworkDirection.PLAY_TO_SERVER)
|
||||
return;
|
||||
ctx.enqueueWork(() -> CommonEvents.leftClickEmpty(ctx.getSender()));
|
||||
ctx.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
if (context.getDirection() != NetworkDirection.PLAY_TO_SERVER)
|
||||
return false;
|
||||
context.enqueueWork(() -> CommonEvents.leftClickEmpty(context.getSender()));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.foundation.networking;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.network.NetworkEvent.Context;
|
||||
|
||||
|
@ -9,6 +7,6 @@ public abstract class SimplePacketBase {
|
|||
|
||||
public abstract void write(FriendlyByteBuf buffer);
|
||||
|
||||
public abstract void handle(Supplier<Context> context);
|
||||
public abstract boolean handle(Context context);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.simibubi.create.foundation.utility;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
|
@ -59,24 +57,21 @@ public class ServerSpeedProvider {
|
|||
public void write(FriendlyByteBuf buffer) {}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<Context> context) {
|
||||
context.get()
|
||||
.enqueueWork(() -> {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
clientTimer = 0;
|
||||
return;
|
||||
}
|
||||
float target = ((float) getSyncInterval()) / Math.max(clientTimer, 1);
|
||||
modifier.chase(Math.min(target, 1), .25, Chaser.EXP);
|
||||
// Set this to -1 because packets are processed before ticks.
|
||||
// ServerSpeedProvider#clientTick will increment it to 0 at the end of this tick.
|
||||
// Setting it to 0 causes consistent desync, as the client ends up counting too many ticks.
|
||||
clientTimer = -1;
|
||||
|
||||
});
|
||||
context.get()
|
||||
.setPacketHandled(true);
|
||||
public boolean handle(Context context) {
|
||||
context.enqueueWork(() -> {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
clientTimer = 0;
|
||||
return;
|
||||
}
|
||||
float target = ((float) getSyncInterval()) / Math.max(clientTimer, 1);
|
||||
modifier.chase(Math.min(target, 1), .25, Chaser.EXP);
|
||||
// Set this to -1 because packets are processed before ticks.
|
||||
// ServerSpeedProvider#clientTick will increment it to 0 at the end of this tick.
|
||||
// Setting it to 0 causes consistent desync, as the client ends up counting too many ticks.
|
||||
clientTimer = -1;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue