Skip to content

Commit

Permalink
1.21 Port XXVII
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Aug 11, 2024
1 parent 547f415 commit 577570c
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.nbt.Tag;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
Expand Down Expand Up @@ -96,6 +97,9 @@ public static EntityType.Builder<?> build(EntityType.Builder<?> builder) {
return entityBuilder;
}

@Override
protected void defineSynchedData(SynchedEntityData.Builder builder) {}

@Override
public void addAdditionalSaveData(CompoundTag p_213281_1_) {
p_213281_1_.putByte("Facing", (byte) this.direction.get3DDataValue());
Expand Down Expand Up @@ -145,16 +149,11 @@ public EntityDimensions getDimensions(Pose pose) {
}

@Override
protected void recalculateBoundingBox() {
if (this.direction == null)
return;
if (this.verticalOrientation == null)
return;

protected AABB calculateBoundingBox(BlockPos blockPos, Direction direction) {
Vec3 pos = Vec3.atLowerCornerOf(getPos())
.add(.5, .5, .5)
.subtract(Vec3.atLowerCornerOf(direction.getNormal())
.scale(0.46875));
.add(.5, .5, .5)
.subtract(Vec3.atLowerCornerOf(direction.getNormal())
.scale(0.46875));
double d1 = pos.x;
double d2 = pos.y;
double d3 = pos.z;
Expand All @@ -163,16 +162,16 @@ protected void recalculateBoundingBox() {
Axis axis = direction.getAxis();
if (size == 2)
pos = pos.add(Vec3.atLowerCornerOf(axis.isHorizontal() ? direction.getCounterClockWise()
.getNormal()
: verticalOrientation.getClockWise()
.getNormal())
.scale(0.5))
.add(Vec3
.atLowerCornerOf(axis.isHorizontal() ? Direction.UP.getNormal()
: direction == Direction.UP ? verticalOrientation.getNormal()
: verticalOrientation.getOpposite()
.getNormal())
.scale(0.5));
.getNormal()
: verticalOrientation.getClockWise()
.getNormal())
.scale(0.5))
.add(Vec3
.atLowerCornerOf(axis.isHorizontal() ? Direction.UP.getNormal()
: direction == Direction.UP ? verticalOrientation.getNormal()
: verticalOrientation.getOpposite()
.getNormal())
.scale(0.5));

d1 = pos.x;
d2 = pos.y;
Expand All @@ -183,20 +182,28 @@ protected void recalculateBoundingBox() {
double d6 = (double) this.getWidth();
Direction.Axis direction$axis = this.direction.getAxis();
switch (direction$axis) {
case X:
d4 = 1.0D;
break;
case Y:
d5 = 1.0D;
break;
case Z:
d6 = 1.0D;
case X:
d4 = 1.0D;
break;
case Y:
d5 = 1.0D;
break;
case Z:
d6 = 1.0D;
}

d4 = d4 / 32.0D;
d5 = d5 / 32.0D;
d6 = d6 / 32.0D;
this.setBoundingBox(new AABB(d1 - d4, d2 - d5, d3 - d6, d1 + d4, d2 + d5, d3 + d6));

return new AABB(d1 - d4, d2 - d5, d3 - d6, d1 + d4, d2 + d5, d3 + d6);
}

@Override
protected void recalculateBoundingBox() {
if (this.direction != null && this.verticalOrientation != null) {
recalculateBoundingBox();
}
}

@Override
Expand Down Expand Up @@ -234,12 +241,10 @@ public boolean survives() {
.isEmpty();
}

@Override
public int getWidth() {
return 16 * size;
}

@Override
public int getHeight() {
return 16 * size;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ProjectileWeaponItem;
import net.minecraft.world.item.TooltipFlag;
Expand Down Expand Up @@ -110,6 +111,12 @@ public boolean isCannon(ItemStack stack) {
return stack.getItem() instanceof PotatoCannonItem;
}

// FIXME 1.21: Projectile shooting
@Override
protected void shootProjectile(LivingEntity shooter, Projectile projectile, int index, float velocity, float inaccuracy, float angle, @Nullable LivingEntity target) {

}

@Override
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import com.simibubi.create.Create;
import com.simibubi.create.foundation.utility.BBHelper;
import com.simibubi.create.foundation.utility.NBTProcessors;
import com.simibubi.create.foundation.utility.ComponentsProcessors;
import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;

import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -77,11 +77,11 @@ public Set<BlockPos> getAllPositions() {
@Override
public boolean addFreshEntity(Entity entityIn) {
if (entityIn instanceof ItemFrame itemFrame)
itemFrame.setItem(NBTProcessors.withUnsafeNBTDiscarded(itemFrame.getItem()));
itemFrame.setItem(ComponentsProcessors.withUnsafeComponentsDiscarded(itemFrame.getItem()));
if (entityIn instanceof ArmorStand armorStand)
for (EquipmentSlot equipmentSlot : EquipmentSlot.values())
armorStand.setItemSlot(equipmentSlot,
NBTProcessors.withUnsafeNBTDiscarded(armorStand.getItemBySlot(equipmentSlot)));
ComponentsProcessors.withUnsafeComponentsDiscarded(armorStand.getItemBySlot(equipmentSlot)));

return entities.add(entityIn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.simibubi.create.foundation.utility.NBTProcessors;
import com.simibubi.create.foundation.utility.ComponentsProcessors;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.decoration.ArmorStand;
Expand Down Expand Up @@ -108,7 +108,7 @@ public static ItemRequirement of(Entity entity) {

if (entity instanceof ItemFrame itemFrame) {
ItemStack frame = new ItemStack(Items.ITEM_FRAME);
ItemStack displayedItem = NBTProcessors.withUnsafeNBTDiscarded(itemFrame.getItem());
ItemStack displayedItem = ComponentsProcessors.withUnsafeComponentsDiscarded(itemFrame.getItem());
if (displayedItem.isEmpty())
return new ItemRequirement(ItemUseType.CONSUME, Items.ITEM_FRAME);
return new ItemRequirement(List.of(new ItemRequirement.StackRequirement(frame, ItemUseType.CONSUME),
Expand All @@ -120,7 +120,7 @@ public static ItemRequirement of(Entity entity) {
requirements.add(new StackRequirement(new ItemStack(Items.ARMOR_STAND), ItemUseType.CONSUME));
armorStand.getAllSlots()
.forEach(s -> requirements
.add(new StrictNbtStackRequirement(NBTProcessors.withUnsafeNBTDiscarded(s), ItemUseType.CONSUME)));
.add(new StrictNbtStackRequirement(ComponentsProcessors.withUnsafeComponentsDiscarded(s), ItemUseType.CONSUME)));
return new ItemRequirement(requirements);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.simibubi.create.foundation.utility;

import net.minecraft.core.component.DataComponents;
import net.minecraft.core.component.TypedDataComponent;
import net.minecraft.world.item.ItemStack;

public class ComponentsProcessors {
public static ItemStack withUnsafeComponentsDiscarded(ItemStack stack) {
if (stack.isComponentsPatchEmpty())
return stack;
ItemStack copy = stack.copy();
stack.getComponents()
.stream()
.filter(ComponentsProcessors::isUnsafeItemComponent)
.map(TypedDataComponent::type)
.forEach(copy::remove);
return copy;
}

public static boolean isUnsafeItemComponent(TypedDataComponent<?> component) {
if (component.type().equals(DataComponents.ENCHANTMENTS))
return false;
if (component.type().equals(DataComponents.POTION_CONTENTS))
return false;
if (component.type().equals(DataComponents.DAMAGE))
return false;
if (component.type().equals(DataComponents.CUSTOM_NAME))
return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@
import com.simibubi.create.AllBlockEntityTypes;

import net.minecraft.core.RegistryAccess;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.component.TypedDataComponent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.EnchantedBookItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
Expand Down Expand Up @@ -78,34 +73,22 @@ public static UnaryOperator<CompoundTag> itemProcessor(String tagKey) {
return data;
HashSet<String> keys = new HashSet<>(itemTag.getAllKeys());
for (String key : keys)
if (isUnsafeItemComponent(key))
if (isUnsafeItemNBTKey(key))
itemTag.remove(key);
if (itemTag.isEmpty())
compound.remove("tag");
return data;
};
}

public static ItemStack withUnsafeNBTDiscarded(ItemStack stack) {
if (stack.getComponents() == DataComponentMap.EMPTY)
return stack;
ItemStack copy = stack.copy();
stack.getComponents()
.stream()
.filter(NBTProcessors::isUnsafeItemComponent)
.forEach(tc -> copy.remove(tc.type()));
return copy;
}

// FIXME 1.21: Make sure this is correct
public static boolean isUnsafeItemComponent(TypedDataComponent<?> component) {
if (component.type().equals(DataComponents.ENCHANTMENTS))
public static boolean isUnsafeItemNBTKey(String name) {
if (name.equals("Enchantments"))
return false;
if (component.type().equals(DataComponents.POTION_CONTENTS))
if (name.contains("Potion"))
return false;
if (component.type().equals(DataComponents.DAMAGE))
if (name.contains("Damage"))
return false;
if (component.type().equals(DataComponents.CUSTOM_NAME))
if (name.equals("display"))
return false;
return true;
}
Expand Down

0 comments on commit 577570c

Please sign in to comment.