Merge branch 'mc1.18/dev' into mc1.19/dev

This commit is contained in:
simibubi 2022-09-23 23:05:45 +02:00
commit 32f72cb614
6 changed files with 97 additions and 44 deletions

View File

@ -33,6 +33,7 @@ import com.simibubi.create.content.curiosities.deco.SlidingDoorBlock;
import com.simibubi.create.content.logistics.trains.entity.CarriageContraption; import com.simibubi.create.content.logistics.trains.entity.CarriageContraption;
import com.simibubi.create.content.logistics.trains.entity.CarriageContraptionEntity; import com.simibubi.create.content.logistics.trains.entity.CarriageContraptionEntity;
import com.simibubi.create.content.logistics.trains.entity.Train; import com.simibubi.create.content.logistics.trains.entity.Train;
import com.simibubi.create.foundation.advancement.AllAdvancements;
import com.simibubi.create.foundation.collision.Matrix3d; import com.simibubi.create.foundation.collision.Matrix3d;
import com.simibubi.create.foundation.mixin.accessor.ServerLevelAccessor; import com.simibubi.create.foundation.mixin.accessor.ServerLevelAccessor;
import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.networking.AllPackets;
@ -181,16 +182,28 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
contraption.getSeatMapping() contraption.getSeatMapping()
.remove(passenger.getUUID()); .remove(passenger.getUUID());
AllPackets.channel.send(PacketDistributor.TRACKING_ENTITY.with(() -> this), AllPackets.channel.send(PacketDistributor.TRACKING_ENTITY.with(() -> this),
new ContraptionSeatMappingPacket(getId(), contraption.getSeatMapping())); new ContraptionSeatMappingPacket(getId(), contraption.getSeatMapping(), passenger.getId()));
} }
@Override @Override
public Vec3 getDismountLocationForPassenger(LivingEntity pLivingEntity) { public Vec3 getDismountLocationForPassenger(LivingEntity entityLiving) {
Vec3 loc = super.getDismountLocationForPassenger(pLivingEntity); Vec3 position = super.getDismountLocationForPassenger(entityLiving);
CompoundTag data = pLivingEntity.getPersistentData(); CompoundTag data = entityLiving.getPersistentData();
if (!data.contains("ContraptionDismountLocation")) if (!data.contains("ContraptionDismountLocation"))
return loc; return position;
return VecHelper.readNBT(data.getList("ContraptionDismountLocation", Tag.TAG_DOUBLE));
position = VecHelper.readNBT(data.getList("ContraptionDismountLocation", Tag.TAG_DOUBLE));
data.remove("ContraptionDismountLocation");
entityLiving.setOnGround(false);
if (!data.contains("ContraptionMountLocation"))
return position;
Vec3 prevPosition = VecHelper.readNBT(data.getList("ContraptionMountLocation", Tag.TAG_DOUBLE));
data.remove("ContraptionMountLocation");
if (entityLiving instanceof Player player && !prevPosition.closerThan(position, 5000))
AllAdvancements.LONG_TRAVEL.awardTo(player);
return position;
} }
@Override @Override
@ -204,7 +217,7 @@ public abstract class AbstractContraptionEntity extends Entity implements IEntit
transformedVector.y + SeatEntity.getCustomEntitySeatOffset(passenger) - 1 / 8f, transformedVector.z); transformedVector.y + SeatEntity.getCustomEntitySeatOffset(passenger) - 1 / 8f, transformedVector.z);
} }
protected Vec3 getPassengerPosition(Entity passenger, float partialTicks) { public Vec3 getPassengerPosition(Entity passenger, float partialTicks) {
UUID id = passenger.getUUID(); UUID id = passenger.getUUID();
if (passenger instanceof OrientedContraptionEntity) { if (passenger instanceof OrientedContraptionEntity) {
BlockPos localPos = contraption.getBearingPosOf(id); BlockPos localPos = contraption.getBearingPosOf(id);

View File

@ -7,7 +7,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.simibubi.create.foundation.advancement.AllAdvancements;
import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.foundation.utility.WorldAttached; import com.simibubi.create.foundation.utility.WorldAttached;
@ -17,7 +16,6 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -65,24 +63,18 @@ public class ContraptionHandler {
} }
public static void entitiesWhoJustDismountedGetSentToTheRightLocation(LivingEntity entityLiving, Level world) { public static void entitiesWhoJustDismountedGetSentToTheRightLocation(LivingEntity entityLiving, Level world) {
if (world.isClientSide) if (!world.isClientSide)
return; return;
CompoundTag data = entityLiving.getPersistentData(); CompoundTag data = entityLiving.getPersistentData();
if (!data.contains("ContraptionDismountLocation")) if (!data.contains("ContraptionDismountLocation"))
return; return;
Vec3 position = VecHelper.readNBT(data.getList("ContraptionDismountLocation", Tag.TAG_DOUBLE)); Vec3 position = VecHelper.readNBT(data.getList("ContraptionDismountLocation", Tag.TAG_DOUBLE));
if (entityLiving.getVehicle() == null) if (entityLiving.getVehicle() == null)
entityLiving.teleportTo(position.x, position.y, position.z); entityLiving.absMoveTo(position.x, position.y, position.z, entityLiving.getYRot(), entityLiving.getXRot());
data.remove("ContraptionDismountLocation"); data.remove("ContraptionDismountLocation");
entityLiving.setOnGround(false); entityLiving.setOnGround(false);
if (!data.contains("ContraptionMountLocation"))
return;
Vec3 prevPosition = VecHelper.readNBT(data.getList("ContraptionMountLocation", Tag.TAG_DOUBLE));
data.remove("ContraptionMountLocation");
if (entityLiving instanceof Player player && !prevPosition.closerThan(position, 5000))
AllAdvancements.LONG_TRAVEL.awardTo(player);
} }
} }

View File

@ -7,24 +7,33 @@ 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;
import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.network.NetworkEvent.Context; import net.minecraftforge.network.NetworkEvent.Context;
public class ContraptionSeatMappingPacket extends SimplePacketBase { public class ContraptionSeatMappingPacket extends SimplePacketBase {
private Map<UUID, Integer> mapping; private Map<UUID, Integer> mapping;
private int entityID; private int entityID;
private int dismountedID;
public ContraptionSeatMappingPacket(int entityID, Map<UUID, Integer> mapping) { public ContraptionSeatMappingPacket(int entityID, Map<UUID, Integer> mapping) {
this(entityID, mapping, -1);
}
public ContraptionSeatMappingPacket(int entityID, Map<UUID, Integer> mapping, int dismountedID) {
this.entityID = entityID; this.entityID = entityID;
this.mapping = mapping; this.mapping = mapping;
this.dismountedID = dismountedID;
} }
public ContraptionSeatMappingPacket(FriendlyByteBuf buffer) { public ContraptionSeatMappingPacket(FriendlyByteBuf buffer) {
entityID = buffer.readInt(); entityID = buffer.readInt();
dismountedID = buffer.readInt();
mapping = new HashMap<>(); mapping = new HashMap<>();
short size = buffer.readShort(); short size = buffer.readShort();
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
@ -34,6 +43,7 @@ public class ContraptionSeatMappingPacket extends SimplePacketBase {
@Override @Override
public void write(FriendlyByteBuf buffer) { public void write(FriendlyByteBuf buffer) {
buffer.writeInt(entityID); buffer.writeInt(entityID);
buffer.writeInt(dismountedID);
buffer.writeShort(mapping.size()); buffer.writeShort(mapping.size());
mapping.forEach((k, v) -> { mapping.forEach((k, v) -> {
buffer.writeUUID(k); buffer.writeUUID(k);
@ -49,6 +59,17 @@ public class ContraptionSeatMappingPacket extends SimplePacketBase {
if (!(entityByID instanceof AbstractContraptionEntity)) if (!(entityByID instanceof AbstractContraptionEntity))
return; return;
AbstractContraptionEntity contraptionEntity = (AbstractContraptionEntity) entityByID; AbstractContraptionEntity contraptionEntity = (AbstractContraptionEntity) entityByID;
if (dismountedID != -1) {
Entity dismountedByID = Minecraft.getInstance().level.getEntity(dismountedID);
if (Minecraft.getInstance().player != dismountedByID)
return;
Vec3 transformedVector = contraptionEntity.getPassengerPosition(dismountedByID, 1);
if (transformedVector != null)
dismountedByID.getPersistentData()
.put("ContraptionDismountLocation", VecHelper.writeNBT(transformedVector));
}
contraptionEntity.getContraption() contraptionEntity.getContraption()
.setSeatMapping(mapping); .setSeatMapping(mapping);
}); });

View File

@ -66,8 +66,7 @@ public class ScheduleItem extends Item implements MenuProvider {
return InteractionResultHolder.pass(heldItem); return InteractionResultHolder.pass(heldItem);
} }
@Override public InteractionResult handScheduleTo(ItemStack pStack, Player pPlayer, LivingEntity pInteractionTarget,
public InteractionResult interactLivingEntity(ItemStack pStack, Player pPlayer, LivingEntity pInteractionTarget,
InteractionHand pUsedHand) { InteractionHand pUsedHand) {
InteractionResult pass = InteractionResult.PASS; InteractionResult pass = InteractionResult.PASS;
@ -123,6 +122,7 @@ public class ScheduleItem extends Item implements MenuProvider {
pStack.shrink(1); pStack.shrink(1);
pPlayer.setItemInHand(pUsedHand, pStack.isEmpty() ? ItemStack.EMPTY : pStack); pPlayer.setItemInHand(pUsedHand, pStack.isEmpty() ? ItemStack.EMPTY : pStack);
} }
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }

View File

@ -11,19 +11,20 @@ import com.simibubi.create.foundation.utility.Lang;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteract; import net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteractSpecific;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
@EventBusSubscriber @EventBusSubscriber
public class ScheduleItemRetrieval { public class ScheduleItemEntityInteraction {
@SubscribeEvent @SubscribeEvent
public static void removeScheduleFromConductor(EntityInteract event) { public static void interactWithConductor(EntityInteractSpecific event) {
Entity entity = event.getTarget(); Entity entity = event.getTarget();
Player player = event.getEntity(); Player player = event.getEntity();
if (player == null || entity == null) if (player == null || entity == null)
@ -34,16 +35,24 @@ public class ScheduleItemRetrieval {
Entity rootVehicle = entity.getRootVehicle(); Entity rootVehicle = entity.getRootVehicle();
if (!(rootVehicle instanceof CarriageContraptionEntity)) if (!(rootVehicle instanceof CarriageContraptionEntity))
return; return;
if (!(entity instanceof LivingEntity living))
return;
if (player.getCooldowns()
.isOnCooldown(AllItems.SCHEDULE.get()))
return;
ItemStack itemStack = event.getItemStack(); ItemStack itemStack = event.getItemStack();
if (AllItems.SCHEDULE.isIn(itemStack) && entity instanceof Wolf wolf) { if (itemStack.getItem()instanceof ScheduleItem si) {
itemStack.getItem() InteractionResult result = si.handScheduleTo(itemStack, player, living, event.getHand());
.interactLivingEntity(itemStack, player, wolf, event.getHand()); if (result.consumesAction()) {
player.getCooldowns()
.addCooldown(AllItems.SCHEDULE.get(), 5);
event.setCancellationResult(result);
event.setCanceled(true);
return; return;
} }
}
if (player.level.isClientSide)
return;
if (event.getHand() == InteractionHand.OFF_HAND) if (event.getHand() == InteractionHand.OFF_HAND)
return; return;
@ -68,22 +77,34 @@ public class ScheduleItemRetrieval {
if (directions == null) if (directions == null)
return; return;
boolean onServer = !event.getWorld().isClientSide;
if (train.runtime.paused && !train.runtime.completed) { if (train.runtime.paused && !train.runtime.completed) {
if (onServer) {
train.runtime.paused = false; train.runtime.paused = false;
AllSoundEvents.CONFIRM.playOnServer(player.level, player.blockPosition(), 1, 1); AllSoundEvents.CONFIRM.playOnServer(player.level, player.blockPosition(), 1, 1);
player.displayClientMessage(Lang.translateDirect("schedule.continued"), true); player.displayClientMessage(Lang.translateDirect("schedule.continued"), true);
}
player.getCooldowns()
.addCooldown(AllItems.SCHEDULE.get(), 5);
event.setCancellationResult(InteractionResult.SUCCESS);
event.setCanceled(true); event.setCanceled(true);
return; return;
} }
ItemStack itemInHand = player.getItemInHand(event.getHand()); ItemStack itemInHand = player.getItemInHand(event.getHand());
if (!itemInHand.isEmpty()) { if (!itemInHand.isEmpty()) {
if (onServer) {
AllSoundEvents.DENY.playOnServer(player.level, player.blockPosition(), 1, 1); AllSoundEvents.DENY.playOnServer(player.level, player.blockPosition(), 1, 1);
player.displayClientMessage(Lang.translateDirect("schedule.remove_with_empty_hand"), true); player.displayClientMessage(Lang.translateDirect("schedule.remove_with_empty_hand"), true);
}
event.setCancellationResult(InteractionResult.SUCCESS);
event.setCanceled(true); event.setCanceled(true);
return; return;
} }
if (onServer) {
AllSoundEvents.playItemPickup(player); AllSoundEvents.playItemPickup(player);
player.displayClientMessage( player.displayClientMessage(
Lang.translateDirect( Lang.translateDirect(
@ -92,7 +113,11 @@ public class ScheduleItemRetrieval {
player.getInventory() player.getInventory()
.placeItemBackInInventory(train.runtime.returnSchedule()); .placeItemBackInInventory(train.runtime.returnSchedule());
// player.setItemInHand(event.getHand(), train.runtime.returnSchedule()); }
player.getCooldowns()
.addCooldown(AllItems.SCHEDULE.get(), 5);
event.setCancellationResult(InteractionResult.SUCCESS);
event.setCanceled(true); event.setCanceled(true);
return; return;
} }

View File

@ -115,6 +115,8 @@ public abstract class EntityContraptionInteractionMixin extends CapabilityProvid
return; return;
if (self.isOnGround()) if (self.isOnGround())
return; return;
if (self.isPassenger())
return;
Vec3 worldPos = self.position() Vec3 worldPos = self.position()
.add(0, -0.2, 0); .add(0, -0.2, 0);