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