use of net.minecraft.nbt.CompoundTag in project Tropicraft by Tropicraft.
the class TropicraftTropicalFishEntity method saveToBucketTag.
/**
* Add extra data to the bucket that just picked this fish up
*/
@Override
public void saveToBucketTag(final ItemStack bucket) {
super.saveToBucketTag(bucket);
CompoundTag compoundnbt = bucket.getOrCreateTag();
compoundnbt.putInt("BucketVariantTag", getFishType().id);
}
use of net.minecraft.nbt.CompoundTag in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method setItemFrameFacingAndRotation.
private static Entity setItemFrameFacingAndRotation(ItemFrame frame, BuildEntity buildEntity, BlockPos entityPos, Structure structure) {
float yaw = frame.getYRot();
Rotation rotation = Rotation.NONE;
double x_axis_offset = buildEntity.entityXAxisOffset;
double z_axis_offset = buildEntity.entityZAxisOffset;
Direction facing = frame.getDirection();
double y_axis_offset = buildEntity.entityYAxisOffset;
x_axis_offset = x_axis_offset * -1;
z_axis_offset = z_axis_offset * -1;
Direction structureDirection = structure.getClearSpace().getShape().getDirection();
Direction configurationDirection = structure.configuration.houseFacing.getOpposite();
if (facing != Direction.UP && facing != Direction.DOWN) {
if (configurationDirection == structureDirection.getOpposite()) {
rotation = Rotation.CLOCKWISE_180;
facing = facing.getOpposite();
} else if (configurationDirection == structureDirection.getClockWise()) {
rotation = Rotation.CLOCKWISE_90;
facing = facing.getClockWise();
} else if (configurationDirection == structureDirection.getCounterClockWise()) {
rotation = Rotation.COUNTERCLOCKWISE_90;
facing = facing.getCounterClockWise();
} else {
x_axis_offset = 0;
z_axis_offset = 0;
}
}
yaw = frame.rotate(rotation);
CompoundTag compound = new CompoundTag();
((HangingEntity) frame).addAdditionalSaveData(compound);
compound.putByte("Facing", (byte) facing.get3DDataValue());
((HangingEntity) frame).readAdditionalSaveData(compound);
StructureEventHandler.updateEntityHangingBoundingBox(frame);
frame.moveTo(entityPos.getX() + x_axis_offset, entityPos.getY() + y_axis_offset, entityPos.getZ() + z_axis_offset, yaw, frame.getXRot());
StructureEventHandler.updateEntityHangingBoundingBox(frame);
ChunkAccess chunk = structure.world.getChunkAt(entityPos);
chunk.setUnsaved(true);
return frame;
}
use of net.minecraft.nbt.CompoundTag in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method onClone.
/**
* This occurs when a player dies and is used to make sure that a player does not get a duplicate starting house.
*
* @param event The player clone event.
*/
@SubscribeEvent
public static void onClone(PlayerEvent.Clone event) {
if (event.getPlayer() instanceof ServerPlayer) {
// Don't add the tag unless the house item was added. This way it can be added if the feature is turned on.
// When the player is cloned, make sure to copy the tag. If this is not done the item can be given to the
// player again if they die before the log out and log back in.
CompoundTag originalTag = event.getOriginal().getPersistentData();
// Use the server configuration to determine if the house should be added for this player.
String startingItem = CommonProxy.proxyConfiguration.serverConfiguration.startingItem;
if (startingItem != null && !startingItem.equalsIgnoreCase("Nothing")) {
if (originalTag.contains(EntityPlayerConfiguration.PLAYER_ENTITY_TAG)) {
CompoundTag newPlayerTag = event.getPlayer().getPersistentData();
newPlayerTag.put(EntityPlayerConfiguration.PLAYER_ENTITY_TAG, originalTag.get(EntityPlayerConfiguration.PLAYER_ENTITY_TAG));
// Send the persist tag to the client.
Prefab.network.sendTo(new PlayerEntityTagMessage(originalTag.getCompound(EntityPlayerConfiguration.PLAYER_ENTITY_TAG)), ((ServerPlayer) event.getPlayer()).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}
}
}
}
use of net.minecraft.nbt.CompoundTag in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method setPaintingFacingAndRotation.
private static Entity setPaintingFacingAndRotation(Painting entity, BuildEntity buildEntity, BlockPos entityPos, Structure structure) {
float yaw = entity.getYRot();
Rotation rotation = Rotation.NONE;
double x_axis_offset = 0;
double z_axis_offset = 0;
Direction facing = entity.getDirection();
double y_axis_offset = buildEntity.entityYAxisOffset * -1;
Direction structureDirection = structure.getClearSpace().getShape().getDirection();
Direction configurationDirection = structure.configuration.houseFacing.getOpposite();
if (configurationDirection == structureDirection.getOpposite()) {
rotation = Rotation.CLOCKWISE_180;
facing = facing.getOpposite();
} else if (configurationDirection == structureDirection.getClockWise()) {
rotation = Rotation.CLOCKWISE_90;
facing = facing.getClockWise();
} else if (configurationDirection == structureDirection.getCounterClockWise()) {
rotation = Rotation.COUNTERCLOCKWISE_90;
facing = facing.getCounterClockWise();
}
int paintingBlockWidth = entity.motive.getWidth() / 16;
int paintingBlockHeight = entity.motive.getHeight() / 16;
if ((paintingBlockHeight > paintingBlockWidth || paintingBlockHeight > 1) && !(paintingBlockWidth == 4 && paintingBlockHeight == 3)) {
y_axis_offset--;
}
yaw = entity.rotate(rotation);
CompoundTag compound = new CompoundTag();
((HangingEntity) entity).addAdditionalSaveData(compound);
compound.putByte("Facing", (byte) facing.get2DDataValue());
((HangingEntity) entity).readAdditionalSaveData(compound);
StructureEventHandler.updateEntityHangingBoundingBox(entity);
entity.moveTo(entityPos.getX() + x_axis_offset, entityPos.getY() + y_axis_offset, entityPos.getZ() + z_axis_offset, yaw, entity.getXRot());
StructureEventHandler.updateEntityHangingBoundingBox(entity);
ChunkAccess chunk = structure.world.getChunkAt(entityPos);
chunk.setUnsaved(true);
return entity;
}
use of net.minecraft.nbt.CompoundTag in project MC-Prefab by Brian-Wuest.
the class StructureTagMessage method decode.
public static StructureTagMessage decode(FriendlyByteBuf buf) {
// This class is very useful in general for writing more complex objects.
CompoundTag tag = buf.readNbt();
StructureTagMessage returnValue = new StructureTagMessage();
returnValue.structureConfig = EnumStructureConfiguration.getFromIdentifier(tag.getInt("config"));
returnValue.tagMessage = tag.getCompound("dataTag");
return returnValue;
}
Aggregations