Player Feedback, Part III
This commit is contained in:
parent
82e922032a
commit
34de9a0319
14 changed files with 298 additions and 82 deletions
|
@ -2,12 +2,39 @@ package com.simibubi.create.content.contraptions.components.structureMovement;
|
|||
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
public class AssemblyException extends Exception {
|
||||
public final ITextComponent component;
|
||||
private BlockPos position = null;
|
||||
|
||||
public static void write(CompoundNBT compound, AssemblyException exception) {
|
||||
if (exception == null)
|
||||
return;
|
||||
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
nbt.putString("Component", ITextComponent.Serializer.toJson(exception.component));
|
||||
if (exception.hasPosition())
|
||||
nbt.putLong("Position", exception.getPosition().toLong());
|
||||
|
||||
compound.put("LastException", nbt);
|
||||
}
|
||||
|
||||
public static AssemblyException read(CompoundNBT compound) {
|
||||
if (!compound.contains("LastException"))
|
||||
return null;
|
||||
|
||||
CompoundNBT nbt = compound.getCompound("LastException");
|
||||
String string = nbt.getString("Component");
|
||||
AssemblyException exception = new AssemblyException(ITextComponent.Serializer.fromJson(string));
|
||||
if (nbt.contains("Position"))
|
||||
exception.position = BlockPos.fromLong(nbt.getLong("Position"));
|
||||
|
||||
return exception;
|
||||
}
|
||||
|
||||
public AssemblyException(ITextComponent component) {
|
||||
this.component = component;
|
||||
|
@ -18,18 +45,22 @@ public class AssemblyException extends Exception {
|
|||
}
|
||||
|
||||
public static AssemblyException unmovableBlock(BlockPos pos, BlockState state) {
|
||||
return new AssemblyException("unmovableBlock",
|
||||
AssemblyException e = new AssemblyException("unmovableBlock",
|
||||
pos.getX(),
|
||||
pos.getY(),
|
||||
pos.getZ(),
|
||||
new TranslationTextComponent(state.getBlock().getTranslationKey()));
|
||||
e.position = pos;
|
||||
return e;
|
||||
}
|
||||
|
||||
public static AssemblyException unloadedChunk(BlockPos pos) {
|
||||
return new AssemblyException("chunkNotLoaded",
|
||||
AssemblyException e = new AssemblyException("chunkNotLoaded",
|
||||
pos.getX(),
|
||||
pos.getY(),
|
||||
pos.getZ());
|
||||
e.position = pos;
|
||||
return e;
|
||||
}
|
||||
|
||||
public static AssemblyException structureTooLarge() {
|
||||
|
@ -49,4 +80,12 @@ public class AssemblyException extends Exception {
|
|||
public String getFormattedText() {
|
||||
return component.getFormattedText();
|
||||
}
|
||||
|
||||
public boolean hasPosition() {
|
||||
return position != null;
|
||||
}
|
||||
|
||||
public BlockPos getPosition() {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import net.minecraft.util.Direction;
|
|||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -298,8 +297,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe
|
|||
compound.putBoolean("Running", running);
|
||||
compound.putFloat("HourAngle", hourAngle);
|
||||
compound.putFloat("MinuteAngle", minuteAngle);
|
||||
if (lastException != null)
|
||||
compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component));
|
||||
AssemblyException.write(compound, lastException);
|
||||
super.write(compound, clientPacket);
|
||||
}
|
||||
|
||||
|
@ -311,10 +309,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity implements IBe
|
|||
running = compound.getBoolean("Running");
|
||||
hourAngle = compound.getFloat("HourAngle");
|
||||
minuteAngle = compound.getFloat("MinuteAngle");
|
||||
if (compound.contains("LastException"))
|
||||
lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException")));
|
||||
else
|
||||
lastException = null;
|
||||
lastException = AssemblyException.read(compound);
|
||||
super.read(compound, clientPacket);
|
||||
|
||||
if (!clientPacket)
|
||||
|
|
|
@ -19,7 +19,6 @@ import net.minecraft.tileentity.TileEntityType;
|
|||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -65,8 +64,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp
|
|||
public void write(CompoundNBT compound, boolean clientPacket) {
|
||||
compound.putBoolean("Running", running);
|
||||
compound.putFloat("Angle", angle);
|
||||
if (lastException != null)
|
||||
compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component));
|
||||
AssemblyException.write(compound, lastException);
|
||||
super.write(compound, clientPacket);
|
||||
}
|
||||
|
||||
|
@ -75,10 +73,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity imp
|
|||
float angleBefore = angle;
|
||||
running = compound.getBoolean("Running");
|
||||
angle = compound.getFloat("Angle");
|
||||
if (compound.contains("LastException"))
|
||||
lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException")));
|
||||
else
|
||||
lastException = null;
|
||||
lastException = AssemblyException.read(compound);
|
||||
super.read(compound, clientPacket);
|
||||
if (!clientPacket)
|
||||
return;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.gantry;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionType;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption;
|
||||
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -21,7 +21,7 @@ public class GantryContraption extends TranslatingContraption {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean assemble(World world, BlockPos pos) {
|
||||
public boolean assemble(World world, BlockPos pos) throws AssemblyException {
|
||||
if (!searchMovedStructure(world, pos, null))
|
||||
return false;
|
||||
startMoving(world);
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.gantry;
|
||||
|
||||
import static net.minecraft.state.properties.BlockStateProperties.FACING;
|
||||
|
||||
import com.simibubi.create.AllBlocks;
|
||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionCollider;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions;
|
||||
import com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock;
|
||||
import com.simibubi.create.content.contraptions.relays.advanced.GantryShaftTileEntity;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class GantryPinionTileEntity extends KineticTileEntity {
|
||||
import static net.minecraft.state.properties.BlockStateProperties.FACING;
|
||||
|
||||
public class GantryPinionTileEntity extends KineticTileEntity implements IDisplayAssemblyExceptions {
|
||||
|
||||
boolean assembleNextTick;
|
||||
protected AssemblyException lastException;
|
||||
|
||||
public GantryPinionTileEntity(TileEntityType<?> typeIn) {
|
||||
super(typeIn);
|
||||
|
@ -50,6 +53,11 @@ public class GantryPinionTileEntity extends KineticTileEntity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssemblyException getLastAssemblyException() {
|
||||
return lastException;
|
||||
}
|
||||
|
||||
private void tryAssemble() {
|
||||
BlockState blockState = getBlockState();
|
||||
if (!(blockState.getBlock() instanceof GantryPinionBlock))
|
||||
|
@ -71,8 +79,17 @@ public class GantryPinionTileEntity extends KineticTileEntity {
|
|||
if (pinionMovementSpeed < 0)
|
||||
movementDirection = movementDirection.getOpposite();
|
||||
|
||||
if (!contraption.assemble(world, pos))
|
||||
try {
|
||||
lastException = null;
|
||||
if (!contraption.assemble(world, pos))
|
||||
return;
|
||||
|
||||
sendData();
|
||||
} catch (AssemblyException e) {
|
||||
lastException = e;
|
||||
sendData();
|
||||
return;
|
||||
}
|
||||
if (ContraptionCollider.isCollidingWithWorld(world, contraption, pos.offset(movementDirection),
|
||||
movementDirection))
|
||||
return;
|
||||
|
@ -85,6 +102,18 @@ public class GantryPinionTileEntity extends KineticTileEntity {
|
|||
world.addEntity(movedContraption);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void write(CompoundNBT compound, boolean clientPacket) {
|
||||
AssemblyException.write(compound, lastException);
|
||||
super.write(compound, clientPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(CompoundNBT compound, boolean clientPacket) {
|
||||
lastException = AssemblyException.read(compound);
|
||||
super.read(compound, clientPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float propagateRotationTo(KineticTileEntity target, BlockState stateFrom, BlockState stateTo, BlockPos diff,
|
||||
boolean connectedViaAxes, boolean connectedViaCogs) {
|
||||
|
|
|
@ -16,7 +16,6 @@ import net.minecraft.state.properties.RailShape;
|
|||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.Direction.Axis;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -50,17 +49,13 @@ public class CartAssemblerTileEntity extends SmartTileEntity implements IDisplay
|
|||
|
||||
@Override
|
||||
public void write(CompoundNBT compound, boolean clientPacket) {
|
||||
if (lastException != null)
|
||||
compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component));
|
||||
AssemblyException.write(compound, lastException);
|
||||
super.write(compound, clientPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read(CompoundNBT compound, boolean clientPacket) {
|
||||
if (compound.contains("LastException"))
|
||||
lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException")));
|
||||
else
|
||||
lastException = null;
|
||||
lastException = AssemblyException.read(compound);
|
||||
super.read(compound, clientPacket);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import net.minecraft.tileentity.TileEntityType;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -158,8 +157,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme
|
|||
compound.putBoolean("Running", running);
|
||||
compound.putBoolean("Waiting", waitingForSpeedChange);
|
||||
compound.putFloat("Offset", offset);
|
||||
if (lastException != null)
|
||||
compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component));
|
||||
AssemblyException.write(compound, lastException);
|
||||
super.write(compound, clientPacket);
|
||||
|
||||
if (clientPacket && forceMove) {
|
||||
|
@ -176,10 +174,7 @@ public abstract class LinearActuatorTileEntity extends KineticTileEntity impleme
|
|||
running = compound.getBoolean("Running");
|
||||
waitingForSpeedChange = compound.getBoolean("Waiting");
|
||||
offset = compound.getFloat("Offset");
|
||||
if (compound.contains("LastException"))
|
||||
lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException")));
|
||||
else
|
||||
lastException = null;
|
||||
lastException = AssemblyException.read(compound);
|
||||
super.read(compound, clientPacket);
|
||||
|
||||
if (!clientPacket)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.simibubi.create.content.contraptions.components.structureMovement.piston;
|
||||
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AllContraptionTypes;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.BlockMovementTraits;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionType;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.TranslatingContraption;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonBlock.*;
|
||||
import com.simibubi.create.foundation.config.AllConfigs;
|
||||
|
|
|
@ -22,7 +22,6 @@ import net.minecraft.util.math.AxisAlignedBB;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
public class PulleyTileEntity extends LinearActuatorTileEntity {
|
||||
|
||||
|
@ -190,18 +189,12 @@ public class PulleyTileEntity extends LinearActuatorTileEntity {
|
|||
@Override
|
||||
protected void read(CompoundNBT compound, boolean clientPacket) {
|
||||
initialOffset = compound.getInt("InitialOffset");
|
||||
if (compound.contains("LastException"))
|
||||
lastException = new AssemblyException(ITextComponent.Serializer.fromJson(compound.getString("LastException")));
|
||||
else
|
||||
lastException = null;
|
||||
super.read(compound, clientPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(CompoundNBT compound, boolean clientPacket) {
|
||||
compound.putInt("InitialOffset", initialOffset);
|
||||
if (lastException != null)
|
||||
compound.putString("LastException", ITextComponent.Serializer.toJson(lastException.component));
|
||||
super.write(compound, clientPacket);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,25 +1,42 @@
|
|||
package com.simibubi.create.foundation.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class AllCommands {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSource> dispatcher) {
|
||||
dispatcher.register(Commands.literal("create")
|
||||
//general purpose
|
||||
.then(ToggleDebugCommand.register())
|
||||
.then(OverlayConfigCommand.register())
|
||||
.then(FixLightingCommand.register())
|
||||
.then(ReplaceInCommandBlocksCommand.register())
|
||||
public static Predicate<CommandSource> sourceIsPlayer = (cs) -> cs.getEntity() instanceof PlayerEntity;
|
||||
|
||||
//dev-util
|
||||
//Comment out for release
|
||||
.then(ClearBufferCacheCommand.register())
|
||||
.then(ChunkUtilCommand.register())
|
||||
// .then(KillTPSCommand.register())
|
||||
public static void register(CommandDispatcher<CommandSource> dispatcher) {
|
||||
|
||||
LiteralCommandNode<CommandSource> createRoot = dispatcher.register(Commands.literal("create")
|
||||
//general purpose
|
||||
.then(ToggleDebugCommand.register())
|
||||
.then(OverlayConfigCommand.register())
|
||||
.then(FixLightingCommand.register())
|
||||
.then(ReplaceInCommandBlocksCommand.register())
|
||||
.then(HighlightCommand.register())
|
||||
|
||||
//dev-util
|
||||
//Comment out for release
|
||||
.then(ClearBufferCacheCommand.register())
|
||||
.then(ChunkUtilCommand.register())
|
||||
//.then(KillTPSCommand.register())
|
||||
);
|
||||
|
||||
CommandNode<CommandSource> c = dispatcher.findNode(Collections.singleton("c"));
|
||||
if (c != null)
|
||||
return;
|
||||
|
||||
dispatcher.register(Commands.literal("c")
|
||||
.redirect(createRoot)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
package com.simibubi.create.foundation.command;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.IDisplayAssemblyExceptions;
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.command.arguments.BlockPosArgument;
|
||||
import net.minecraft.command.arguments.EntityArgument;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class HighlightCommand {
|
||||
|
||||
public static ArgumentBuilder<CommandSource, ?> register() {
|
||||
return Commands.literal("highlight")
|
||||
.requires(cs -> cs.hasPermissionLevel(0))
|
||||
.requires(AllCommands.sourceIsPlayer)
|
||||
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
||||
.requires(AllCommands.sourceIsPlayer)
|
||||
.executes(ctx -> {
|
||||
BlockPos pos = BlockPosArgument.getLoadedBlockPos(ctx, "pos");
|
||||
|
||||
AllPackets.channel.send(
|
||||
PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) ctx.getSource().getEntity()),
|
||||
new HighlightPacket(pos)
|
||||
);
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
.then(Commands.argument("players", EntityArgument.players())
|
||||
.executes(ctx -> {
|
||||
Collection<ServerPlayerEntity> players = EntityArgument.getPlayers(ctx, "players");
|
||||
BlockPos pos = BlockPosArgument.getBlockPos(ctx, "pos");
|
||||
|
||||
for (ServerPlayerEntity p : players) {
|
||||
AllPackets.channel.send(
|
||||
PacketDistributor.PLAYER.with(() -> p),
|
||||
new HighlightPacket(pos)
|
||||
);
|
||||
}
|
||||
|
||||
return players.size();
|
||||
})
|
||||
)
|
||||
)
|
||||
.executes(ctx -> {
|
||||
ServerPlayerEntity player = ctx.getSource().asPlayer();
|
||||
return highlightAssemblyExceptionFor(player, ctx.getSource());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private static void sendMissMessage(CommandSource source) {
|
||||
source.sendFeedback(new StringTextComponent("Try looking at a Block that has failed to assemble a Contraption and try again."), true);
|
||||
}
|
||||
|
||||
private static int highlightAssemblyExceptionFor(ServerPlayerEntity player, CommandSource source) {
|
||||
double distance = player.getAttribute(PlayerEntity.REACH_DISTANCE).getValue();
|
||||
Vec3d start = player.getEyePosition(1);
|
||||
Vec3d look = player.getLook(1);
|
||||
Vec3d end = start.add(look.x * distance, look.y * distance, look.z * distance);
|
||||
World world = player.world;
|
||||
|
||||
BlockRayTraceResult ray = world.rayTraceBlocks(new RayTraceContext(start, end, RayTraceContext.BlockMode.OUTLINE, RayTraceContext.FluidMode.NONE, player));
|
||||
if (ray.getType() == RayTraceResult.Type.MISS) {
|
||||
sendMissMessage(source);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BlockPos pos = ray.getPos();
|
||||
TileEntity te = world.getTileEntity(pos);
|
||||
if (!(te instanceof IDisplayAssemblyExceptions)) {
|
||||
sendMissMessage(source);
|
||||
return 0;
|
||||
}
|
||||
|
||||
IDisplayAssemblyExceptions display = (IDisplayAssemblyExceptions) te;
|
||||
AssemblyException exception = display.getLastAssemblyException();
|
||||
if (exception == null) {
|
||||
sendMissMessage(source);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!exception.hasPosition()) {
|
||||
source.sendFeedback(new StringTextComponent("Can't highlight a specific position for this issue"), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
BlockPos p = exception.getPosition();
|
||||
String command = "/create highlight " + p.getX() + " " + p.getY() + " " + p.getZ();
|
||||
return player.server.getCommandManager().handleCommand(source, command);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.simibubi.create.foundation.command;
|
||||
|
||||
import com.simibubi.create.AllSpecialTextures;
|
||||
import com.simibubi.create.CreateClient;
|
||||
import com.simibubi.create.foundation.networking.SimplePacketBase;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.network.NetworkEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class HighlightPacket extends SimplePacketBase {
|
||||
|
||||
private final BlockPos pos;
|
||||
|
||||
public HighlightPacket(BlockPos pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public HighlightPacket(PacketBuffer buffer) {
|
||||
this.pos = BlockPos.fromLong(buffer.readLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketBuffer buffer) {
|
||||
buffer.writeLong(pos.toLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Supplier<NetworkEvent.Context> ctx) {
|
||||
ctx.get().enqueueWork(() -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
|
||||
performHighlight(pos);
|
||||
}));
|
||||
|
||||
ctx.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static void performHighlight(BlockPos pos) {
|
||||
if (Minecraft.getInstance().world == null || !Minecraft.getInstance().world.isBlockPresent(pos))
|
||||
return;
|
||||
|
||||
CreateClient.outliner.showAABB("highlightCommand", VoxelShapes.fullCube().getBoundingBox().offset(pos), 200)
|
||||
.lineWidth(1 / 32f)
|
||||
.colored(0xEeEeEe)
|
||||
//.colored(0x243B50)
|
||||
.withFaceTexture(AllSpecialTextures.SELECTION);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,19 +1,11 @@
|
|||
package com.simibubi.create.foundation.networking;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionDisassemblyPacket;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionStallPacket;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryContraptionUpdatePacket;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.glue.GlueEffectPacket;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.sync.ClientMotionPacket;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.sync.ContraptionFluidPacket;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.sync.ContraptionInteractionPacket;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.sync.ContraptionSeatMappingPacket;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.sync.LimbSwingUpdatePacket;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.sync.*;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.train.CouplingCreationPacket;
|
||||
import com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartControllerUpdatePacket;
|
||||
import com.simibubi.create.content.contraptions.fluids.actors.FluidSplashPacket;
|
||||
|
@ -25,16 +17,12 @@ import com.simibubi.create.content.logistics.block.mechanicalArm.ArmPlacementPac
|
|||
import com.simibubi.create.content.logistics.item.filter.FilterScreenPacket;
|
||||
import com.simibubi.create.content.logistics.packet.ConfigureFlexcratePacket;
|
||||
import com.simibubi.create.content.logistics.packet.ConfigureStockswitchPacket;
|
||||
import com.simibubi.create.content.schematics.packet.ConfigureSchematicannonPacket;
|
||||
import com.simibubi.create.content.schematics.packet.InstantSchematicPacket;
|
||||
import com.simibubi.create.content.schematics.packet.SchematicPlacePacket;
|
||||
import com.simibubi.create.content.schematics.packet.SchematicSyncPacket;
|
||||
import com.simibubi.create.content.schematics.packet.SchematicUploadPacket;
|
||||
import com.simibubi.create.content.schematics.packet.*;
|
||||
import com.simibubi.create.foundation.command.ConfigureConfigPacket;
|
||||
import com.simibubi.create.foundation.command.HighlightPacket;
|
||||
import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringCountUpdatePacket;
|
||||
import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueUpdatePacket;
|
||||
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
|
||||
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -46,8 +34,12 @@ import net.minecraftforge.fml.network.PacketDistributor;
|
|||
import net.minecraftforge.fml.network.PacketDistributor.TargetPoint;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
|
||||
import static net.minecraftforge.fml.network.NetworkDirection.PLAY_TO_SERVER;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.minecraftforge.fml.network.NetworkDirection.PLAY_TO_CLIENT;
|
||||
import static net.minecraftforge.fml.network.NetworkDirection.PLAY_TO_SERVER;
|
||||
|
||||
public enum AllPackets {
|
||||
|
||||
|
@ -85,6 +77,7 @@ public enum AllPackets {
|
|||
FLUID_SPLASH(FluidSplashPacket.class, FluidSplashPacket::new, PLAY_TO_CLIENT),
|
||||
CONTRAPTION_FLUID(ContraptionFluidPacket.class, ContraptionFluidPacket::new, PLAY_TO_CLIENT),
|
||||
GANTRY_UPDATE(GantryContraptionUpdatePacket.class, GantryContraptionUpdatePacket::new, PLAY_TO_CLIENT),
|
||||
BLOCK_HIGHLIGHT(HighlightPacket.class, HighlightPacket::new, PLAY_TO_CLIENT)
|
||||
|
||||
;
|
||||
|
||||
|
|
|
@ -1,24 +1,18 @@
|
|||
package com.simibubi.create.foundation.utility.outliner;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.simibubi.create.foundation.renderState.SuperRenderTypeBuffer;
|
||||
import com.simibubi.create.foundation.tileEntity.behaviour.ValueBox;
|
||||
import com.simibubi.create.foundation.utility.outliner.LineOutline.EndChasingLineOutline;
|
||||
import com.simibubi.create.foundation.utility.outliner.Outline.OutlineParams;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Outliner {
|
||||
|
||||
final Map<Object, OutlineEntry> outlines;
|
||||
|
@ -57,6 +51,13 @@ public class Outliner {
|
|||
return entry.outline.getParams();
|
||||
}
|
||||
|
||||
public OutlineParams showAABB(Object slot, AxisAlignedBB bb, int ttl) {
|
||||
createAABBOutlineIfMissing(slot, bb);
|
||||
ChasingAABBOutline outline = getAndRefreshAABB(slot, ttl);
|
||||
outline.prevBB = outline.targetBB = bb;
|
||||
return outline.getParams();
|
||||
}
|
||||
|
||||
public OutlineParams showAABB(Object slot, AxisAlignedBB bb) {
|
||||
createAABBOutlineIfMissing(slot, bb);
|
||||
ChasingAABBOutline outline = getAndRefreshAABB(slot);
|
||||
|
@ -112,6 +113,12 @@ public class Outliner {
|
|||
return (ChasingAABBOutline) entry.getOutline();
|
||||
}
|
||||
|
||||
private ChasingAABBOutline getAndRefreshAABB(Object slot, int ttl) {
|
||||
OutlineEntry entry = outlines.get(slot);
|
||||
entry.ticksTillRemoval = ttl;
|
||||
return (ChasingAABBOutline) entry.getOutline();
|
||||
}
|
||||
|
||||
// Maintenance
|
||||
|
||||
public Outliner() {
|
||||
|
|
Loading…
Reference in a new issue