Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
9 changes: 4 additions & 5 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static List<ItemStack> getListOfStackForEntity(final Entity entity)

// process entity itself
final ItemStack spawnItem = getEntitySpawningItem(entity);
if (spawnItem != null && !(spawnItem.getItem() instanceof SpawnEggItem))
if (spawnItem != null && !(spawnItem.getItem() instanceof SpawnEggItem)) // TODO: 1.22 remove this here and move it to mcol
{
request.add(spawnItem);
}
Expand Down
38 changes: 32 additions & 6 deletions src/main/java/com/ldtteam/structurize/blueprints/v1/Blueprint.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import net.minecraft.nbt.Tag;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.decoration.HangingEntity;
import net.minecraft.world.entity.decoration.BlockAttachedEntity;
import net.minecraft.world.entity.decoration.Painting;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -801,13 +802,28 @@ private static CompoundTag transformEntityInfoWithSettings(final CompoundTag ent
{
finalEntity.load(entityInfo);

final Vec3 entityVec = rotationMirror
.applyToPos(
finalEntity instanceof HangingEntity hang ? Vec3.atCenterOf(hang.getPos()) : finalEntity.position())
.add(Vec3.atLowerCornerOf(pos));
Vec3 source = finalEntity.position();
if (finalEntity instanceof BlockAttachedEntity attachedEntity)
{
source = Vec3.atCenterOf(attachedEntity.getPos());
}
if (finalEntity instanceof Painting painting)
{
source = paitingToMiddle(painting);
}

Vec3 target = rotationMirror.applyToPos(source).add(Vec3.atLowerCornerOf(pos));

finalEntity.setYRot(finalEntity.mirror(rotationMirror.mirror()));
finalEntity.setYRot(finalEntity.rotate(rotationMirror.rotation()));
finalEntity.moveTo(entityVec.x, entityVec.y, entityVec.z, finalEntity.getYRot(), finalEntity.getXRot());
finalEntity.moveTo(target.x, target.y, target.z, finalEntity.getYRot(), finalEntity.getXRot());

if (finalEntity instanceof Painting painting)
{
// first we need painting to be at correct state (aabb, direction etc.), then we can fix it
target = paitingFromMiddle(painting, target);
finalEntity.moveTo(target.x, target.y, target.z, finalEntity.getYRot(), finalEntity.getXRot());
}

final CompoundTag newEntityInfo = new CompoundTag();
finalEntity.save(newEntityInfo);
Expand All @@ -823,6 +839,16 @@ private static CompoundTag transformEntityInfoWithSettings(final CompoundTag ent
return null;
}

private static Vec3 paitingToMiddle(Painting painting)
{
return painting.getBoundingBox().getCenter();
}

private static Vec3 paitingFromMiddle(Painting painting, Vec3 middle)
{
return middle.add(Vec3.atLowerCornerOf(painting.getPos()).subtract(painting.getBoundingBox().getCenter()));
}

private int getVolume()
{
return (int) sizeX * sizeY * sizeZ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.ldtteam.blockui.views.ScrollingList;
import com.ldtteam.blockui.views.View;
import com.ldtteam.structurize.api.ItemStorage;
import com.ldtteam.structurize.api.constants.Constants;
import com.ldtteam.structurize.blockentities.interfaces.IBlueprintDataProviderBE;
import com.ldtteam.structurize.network.messages.*;
import com.ldtteam.structurize.placement.handlers.entity.EntityHandlers;
Expand All @@ -17,16 +16,13 @@
import com.ldtteam.structurize.storage.rendering.types.BoxPreviewData;
import com.ldtteam.structurize.util.BlockUtils;
import com.ldtteam.structurize.util.ScanToolData;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
Expand Down
102 changes: 48 additions & 54 deletions src/main/java/com/ldtteam/structurize/placement/StructurePlacer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ldtteam.structurize.placement;

import com.ldtteam.structurize.Structurize;
import com.ldtteam.structurize.api.ItemStackUtils;
import com.ldtteam.structurize.api.Log;
import com.ldtteam.structurize.blockentities.BlockEntityTagSubstitution;
import com.ldtteam.structurize.blocks.ModBlocks;
Expand All @@ -14,11 +13,8 @@
import com.ldtteam.structurize.util.ChangeStorage;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.Display;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.decoration.HangingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AirBlock;
Expand All @@ -31,8 +27,6 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -350,67 +344,67 @@ public BlockPlacementResult handleEntitySpawn(
final BlockPos worldPos,
final BlockPos localPos,
final ChangeStorage storage,
final boolean simulate)
final boolean simulate)
{
final BlockPos zeroPos = this.handler.getWorldPos().subtract(handler.getBluePrint().getPrimaryBlockOffset());

nextEntity:
for (final CompoundTag compound : this.iterator.getBluePrintPositionInfo(localPos).getEntities())
{
if (compound != null)
try
{
try
final Optional<EntityType<?>> type = compound == null ? Optional.empty() : EntityType.by(compound);
if (type.isEmpty())
{
final BlockPos zeroPos = this.handler.getWorldPos().subtract(handler.getBluePrint().getPrimaryBlockOffset());
continue;
}

final Optional<EntityType<?>> type = EntityType.by(compound);
if (type.isPresent())
{
final Entity entity = type.get().create(world);
if (entity != null)
{
entity.load(compound);

entity.setUUID(UUID.randomUUID());

IEntityHandler.ActionProcessingResult finalResult = IEntityHandler.ActionProcessingResult.DENY;
List<ItemStack> requiredItems = List.of();
for (final IEntityHandler entityHandler : EntityHandlers.handlers)
{
final IEntityHandler.ActionProcessingResult result = entityHandler.checkPlacement(handler, entity, zeroPos);
if (result != IEntityHandler.ActionProcessingResult.PASS)
{
finalResult = result;
requiredItems = entityHandler.getRequiredItems(entity).stream()
.filter(stack -> !stack.isEmpty()).toList();
break;
}
}
if (finalResult != IEntityHandler.ActionProcessingResult.SUCCESS)
{
continue;
}
final Entity entity = type.get().create(world);
if (entity == null)
{
continue;
}

if (!handler.isCreative() && !handler.hasRequiredItems(requiredItems))
{
return new BlockPlacementResult(worldPos, BlockPlacementResult.Result.MISSING_ITEMS, requiredItems);
}
entity.load(compound);

if (!simulate)
{
world.addFreshEntity(entity);
this.handler.consume(requiredItems);
this.handler.triggerEntitySuccess(localPos, requiredItems, true);
}
if (storage != null)
{
storage.addToBeKilledEntity(entity);
}
}
entity.setUUID(UUID.randomUUID());

List<ItemStack> requiredItems = List.of();
nextHandler:
for (final IEntityHandler entityHandler : EntityHandlers.handlers)
{
switch (entityHandler.checkPlacement(handler, entity, zeroPos))
{
case DENY:
continue nextEntity;
case PASS:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure thr logic here is correct ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just random refactor, I'm kinda sure it's correct, just java and nested for loops, we want to switch to normal registry stuff here, and extend it with findHandlerFor(T value) which will return proper instance - to avoid having the search stuff everywhere

continue nextHandler;
case SUCCESS:
requiredItems = entityHandler.getRequiredItems(entity).stream().filter(stack -> !stack.isEmpty()).toList();
break nextHandler;
}
}
catch (final RuntimeException e)

if (!handler.isCreative() && !handler.hasRequiredItems(requiredItems))
{
return new BlockPlacementResult(worldPos, BlockPlacementResult.Result.MISSING_ITEMS, requiredItems);
}

if (!simulate)
{
world.addFreshEntity(entity);
this.handler.consume(requiredItems);
this.handler.triggerEntitySuccess(localPos, requiredItems, true);
}
if (storage != null)
{
Log.getLogger().info("Couldn't restore entity", e);
storage.addToBeKilledEntity(entity);
}
}
catch (final RuntimeException e)
{
Log.getLogger().info("Couldn't restore entity", e);
}
}

return new BlockPlacementResult(worldPos, BlockPlacementResult.Result.SUCCESS);
Expand Down
Loading