fixed player deletion bug, added options for entity (dis)placement
This commit is contained in:
@@ -7,8 +7,10 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.network.MessageType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@@ -73,6 +75,16 @@ public class MyItem extends Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!tag.contains("replaceEntities", 99) || tag.getBoolean("replaceEntities")) {
|
||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.replaceEntities"));
|
||||
} else {
|
||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.doNotReplaceEntities"));
|
||||
}
|
||||
if (!tag.contains("placeEntities", 99) || tag.getBoolean("placeEntities")) {
|
||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.placeEntities"));
|
||||
} else {
|
||||
texts.add(new TranslatableText("item.structure_item.item.tooltip.doNotPlaceEntities"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,6 +165,12 @@ public class MyItem extends Item {
|
||||
}
|
||||
|
||||
MyPlacementSettings ps = (new MyPlacementSettings());
|
||||
if (tag.contains("replaceEntities", 99)) {
|
||||
ps.setReplaceEntities(tag.getBoolean("replaceEntities"));
|
||||
}
|
||||
if (tag.contains("placeEntities", 99)) {
|
||||
ps.setIgnoreEntities(!tag.getBoolean("placeEntities"));
|
||||
}
|
||||
if (tag.contains("blacklist", 9)) {
|
||||
ListTag bl = tag.getList("blacklist", 8);
|
||||
List<Block> blacklist = Lists.newArrayList();
|
||||
@@ -175,7 +193,12 @@ public class MyItem extends Item {
|
||||
.setMirror(BlockMirror.NONE)
|
||||
.setRotation(BlockRotation.NONE)
|
||||
.setChunkPosition(null);
|
||||
boolean success = x.place((ServerWorld)c.getWorld(), loc, loc, ps, c.getWorld().getRandom(), 2);
|
||||
boolean success = false;
|
||||
try {
|
||||
if(x.place((ServerWorld)c.getWorld(), loc, loc, ps, c.getWorld().getRandom(), 2))
|
||||
success = true;
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
if (success) {
|
||||
c.getStack().decrement(1);
|
||||
return ActionResult.SUCCESS;
|
||||
|
||||
@@ -3,6 +3,7 @@ package quimufu.structure_item;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.structure.Structure;
|
||||
import net.minecraft.structure.StructurePlacementData;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -16,6 +17,7 @@ public class MyPlacementSettings extends StructurePlacementData {
|
||||
private List<Block> blacklist;
|
||||
private World world;
|
||||
private BlockPos size;
|
||||
private boolean replaceEntities = true;
|
||||
|
||||
public void forbidOverwrite(List<Block> blocks) {
|
||||
if (blocks.size() == 0) {
|
||||
@@ -41,18 +43,10 @@ public class MyPlacementSettings extends StructurePlacementData {
|
||||
return super.getRandomBlockInfos(blocks, pos);
|
||||
}
|
||||
|
||||
List<Structure.PalettedBlockInfoList> eligibleStructures = new ArrayList<>();
|
||||
if (blacklist == null) {
|
||||
eligibleStructures = blocks;
|
||||
} else {
|
||||
for (Structure.PalettedBlockInfoList struct : blocks) {
|
||||
if (isValid(struct, pos)) {
|
||||
eligibleStructures.add(struct);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Structure.PalettedBlockInfoList> eligibleStructures;
|
||||
eligibleStructures = getEligibleStructures(blocks, pos);
|
||||
if (eligibleStructures.size() == 0)
|
||||
setIgnoreEntities(true);
|
||||
return null;
|
||||
Structure.PalettedBlockInfoList randomBlockInfos = super.getRandomBlockInfos(eligibleStructures, pos);
|
||||
List<Structure.StructureBlockInfo> locs = randomBlockInfos.getAll();
|
||||
if (!locs.isEmpty()) {
|
||||
@@ -60,7 +54,7 @@ public class MyPlacementSettings extends StructurePlacementData {
|
||||
for (Structure.StructureBlockInfo blockInfo : locs) {
|
||||
BlockPos posToClean = blockInfo.pos.add(pos);
|
||||
for (Entity e : entitiesWithinAABB) {
|
||||
if (e.getBoundingBox().intersects(new Box(posToClean))) {
|
||||
if (!(e instanceof PlayerEntity) && e.getBoundingBox().intersects(new Box(posToClean))) {
|
||||
e.remove();
|
||||
}
|
||||
}
|
||||
@@ -69,18 +63,43 @@ public class MyPlacementSettings extends StructurePlacementData {
|
||||
return randomBlockInfos;
|
||||
}
|
||||
|
||||
private List<Structure.PalettedBlockInfoList> getEligibleStructures(List<Structure.PalettedBlockInfoList> blocks, BlockPos pos) {
|
||||
List<Structure.PalettedBlockInfoList> eligibleStructures = new ArrayList<>();
|
||||
if (blacklist == null && shouldReplaceEntities()) {
|
||||
eligibleStructures = blocks;
|
||||
} else {
|
||||
for (Structure.PalettedBlockInfoList struct : blocks) {
|
||||
if (isValid(struct, pos)) {
|
||||
eligibleStructures.add(struct);
|
||||
}
|
||||
}
|
||||
}
|
||||
return eligibleStructures;
|
||||
}
|
||||
|
||||
private boolean isValid(Structure.PalettedBlockInfoList struct, BlockPos pos) {
|
||||
List<Entity> entitiesWithinAABB = world.getNonSpectatingEntities(shouldReplaceEntities()?PlayerEntity.class:Entity.class, new Box(pos,pos.add(size)));
|
||||
for (Structure.StructureBlockInfo bi : struct.getAll()) {
|
||||
BlockPos posToCheck = bi.pos.add(pos);
|
||||
if (World.isValid(posToCheck)) {
|
||||
Block blockToCheck = world.getBlockState(posToCheck).getBlock();
|
||||
for (Block b : blacklist) {
|
||||
if (blockToCheck.equals(b)) {
|
||||
for (Entity e : entitiesWithinAABB) {
|
||||
if (e.getBoundingBox().intersects(new Box(posToCheck))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Block blockToCheck = world.getBlockState(posToCheck).getBlock();
|
||||
if(blacklist.contains(blockToCheck))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean shouldReplaceEntities() {
|
||||
return replaceEntities;
|
||||
}
|
||||
|
||||
public void setReplaceEntities(boolean replaceEntities) {
|
||||
this.replaceEntities = replaceEntities;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"items.structure.spawner.invalid.block.clicked": "Digga %s is net %s, maan.",
|
||||
"items.structure.spawner.invalid.location": "An irreplaceable block is in the way!",
|
||||
"items.structure.spawner.invalid.location": "Something is in the way!",
|
||||
"items.structure.spawner.invalid.structure.name": "Invalid structure name",
|
||||
"items.structure.spawner.structure.nonexistent": "Structure: %s does not exist",
|
||||
"items.structure.spawner.invalid.block": "Block %s invalid",
|
||||
@@ -14,5 +14,9 @@
|
||||
"item.structure_item.item.tooltip.xyz":" x: %s y: %s z: %s",
|
||||
"item.structure_item.item.tooltip.dynamic.offset": "Dynamic offset",
|
||||
"item.structure_item.item.tooltip.blacklist": "Blacklist:",
|
||||
"item.structure_item.item.tooltip.blacklist.more": " And %s more..."
|
||||
"item.structure_item.item.tooltip.blacklist.more": " And %s more...",
|
||||
"item.structure_item.item.tooltip.replaceEntities": "Deletes Entities in the way",
|
||||
"item.structure_item.item.tooltip.doNotReplaceEntities": "Doesn't allow placement with Entities in the way",
|
||||
"item.structure_item.item.tooltip.placeEntities": "Places contained Entities",
|
||||
"item.structure_item.item.tooltip.doNotPlaceEntities": "Doesn't place contained Entities"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user