Different item keys (WIP)
This commit is contained in:
parent
269821dee8
commit
2fabb39f41
4 changed files with 54 additions and 22 deletions
|
@ -87,6 +87,7 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
|
||||||
MinecraftServer server = ((ServerWorld) world).getServer();
|
MinecraftServer server = ((ServerWorld) world).getServer();
|
||||||
ServerWorld destination = isOverworld ? server.getWorld(World.END) : EndPortals.getWorld(server, state.get(PORTAL));
|
ServerWorld destination = isOverworld ? server.getWorld(World.END) : EndPortals.getWorld(server, state.get(PORTAL));
|
||||||
BlockPos exitPos = this.findExitPos(destination, pos, entity);
|
BlockPos exitPos = this.findExitPos(destination, pos, entity);
|
||||||
|
System.out.println(exitPos);
|
||||||
if (exitPos == null) return;
|
if (exitPos == null) return;
|
||||||
if (entity instanceof ServerPlayerEntity) {
|
if (entity instanceof ServerPlayerEntity) {
|
||||||
ServerPlayerEntity player = (ServerPlayerEntity) entity;
|
ServerPlayerEntity player = (ServerPlayerEntity) entity;
|
||||||
|
@ -124,7 +125,7 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
|
||||||
Registry<DimensionType> registry = world.getRegistryManager().getDimensionTypes();
|
Registry<DimensionType> registry = world.getRegistryManager().getDimensionTypes();
|
||||||
double mult = Objects.requireNonNull(registry.get(DimensionType.THE_END_ID)).getCoordinateScale();
|
double mult = Objects.requireNonNull(registry.get(DimensionType.THE_END_ID)).getCoordinateScale();
|
||||||
BlockPos.Mutable basePos;
|
BlockPos.Mutable basePos;
|
||||||
if (world.getRegistryKey().equals(World.OVERWORLD)) {
|
if (!world.getRegistryKey().equals(World.END)) {
|
||||||
basePos = pos.mutableCopy().set(pos.getX() / mult, pos.getY(), pos.getZ() / mult);
|
basePos = pos.mutableCopy().set(pos.getX() / mult, pos.getY(), pos.getZ() / mult);
|
||||||
} else {
|
} else {
|
||||||
basePos = pos.mutableCopy().set(pos.getX() * mult, pos.getY(), pos.getZ() * mult);
|
basePos = pos.mutableCopy().set(pos.getX() * mult, pos.getY(), pos.getZ() * mult);
|
||||||
|
|
|
@ -9,13 +9,16 @@ import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.loot.context.LootContext;
|
import net.minecraft.loot.context.LootContext;
|
||||||
import net.minecraft.loot.context.LootContextParameters;
|
import net.minecraft.loot.context.LootContextParameters;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.state.property.BooleanProperty;
|
import net.minecraft.state.property.BooleanProperty;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldAccess;
|
import net.minecraft.world.WorldAccess;
|
||||||
|
@ -23,7 +26,7 @@ import net.minecraft.world.explosion.Explosion;
|
||||||
import ru.betterend.blocks.basis.PedestalBlock;
|
import ru.betterend.blocks.basis.PedestalBlock;
|
||||||
import ru.betterend.blocks.entities.EternalPedestalEntity;
|
import ru.betterend.blocks.entities.EternalPedestalEntity;
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
import ru.betterend.registry.EndItems;
|
import ru.betterend.registry.EndPortals;
|
||||||
import ru.betterend.rituals.EternalRitual;
|
import ru.betterend.rituals.EternalRitual;
|
||||||
|
|
||||||
public class EternalPedestal extends PedestalBlock {
|
public class EternalPedestal extends PedestalBlock {
|
||||||
|
@ -43,12 +46,15 @@ public class EternalPedestal extends PedestalBlock {
|
||||||
if (pedestal.isEmpty() && updatedState.get(ACTIVATED)) {
|
if (pedestal.isEmpty() && updatedState.get(ACTIVATED)) {
|
||||||
if (pedestal.hasRitual()) {
|
if (pedestal.hasRitual()) {
|
||||||
EternalRitual ritual = pedestal.getRitual();
|
EternalRitual ritual = pedestal.getRitual();
|
||||||
ritual.removePortal();
|
Item item = pedestal.getStack(0).getItem();
|
||||||
|
int dim = EndPortals.getPortalState(Registry.ITEM.getId(item));
|
||||||
|
ritual.removePortal(dim);
|
||||||
}
|
}
|
||||||
world.setBlockState(pos, updatedState.with(ACTIVATED, false));
|
world.setBlockState(pos, updatedState.with(ACTIVATED, false));
|
||||||
} else {
|
} else {
|
||||||
ItemStack itemStack = pedestal.getStack(0);
|
ItemStack itemStack = pedestal.getStack(0);
|
||||||
if (itemStack.getItem() == EndItems.ETERNAL_CRYSTAL) {
|
Identifier id = Registry.ITEM.getId(itemStack.getItem());
|
||||||
|
if (EndPortals.isAvailableItem(id)) {
|
||||||
world.setBlockState(pos, updatedState.with(ACTIVATED, true));
|
world.setBlockState(pos, updatedState.with(ACTIVATED, true));
|
||||||
if (pedestal.hasRitual()) {
|
if (pedestal.hasRitual()) {
|
||||||
pedestal.getRitual().checkStructure();
|
pedestal.getRitual().checkStructure();
|
||||||
|
|
|
@ -65,6 +65,15 @@ public class EndPortals {
|
||||||
return portals[state].color;
|
return portals[state].color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isAvailableItem(Identifier item) {
|
||||||
|
for (int i = 0; i < portals.length; i++) {
|
||||||
|
if (portals[i].item.equals(item)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static JsonObject makeDefault(File file) {
|
private static JsonObject makeDefault(File file) {
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
JsonFactory.storeJson(file, jsonObject);
|
JsonFactory.storeJson(file, jsonObject);
|
||||||
|
@ -119,6 +128,7 @@ public class EndPortals {
|
||||||
JsonObject toJson() {
|
JsonObject toJson() {
|
||||||
JsonObject obj = new JsonObject();
|
JsonObject obj = new JsonObject();
|
||||||
obj.addProperty("dimension", dimension.toString());
|
obj.addProperty("dimension", dimension.toString());
|
||||||
|
obj.addProperty("item", item.toString());
|
||||||
obj.addProperty("colorRed", (color >> 16) & 255);
|
obj.addProperty("colorRed", (color >> 16) & 255);
|
||||||
obj.addProperty("colorGreen", (color >> 8) & 255);
|
obj.addProperty("colorGreen", (color >> 8) & 255);
|
||||||
obj.addProperty("colorBlue", color & 255);
|
obj.addProperty("colorBlue", color & 255);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.google.common.collect.Sets;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Material;
|
import net.minecraft.block.Material;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtHelper;
|
import net.minecraft.nbt.NbtHelper;
|
||||||
import net.minecraft.particle.BlockStateParticleEffect;
|
import net.minecraft.particle.BlockStateParticleEffect;
|
||||||
|
@ -23,7 +24,6 @@ import net.minecraft.state.property.BooleanProperty;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.util.registry.RegistryKey;
|
|
||||||
import net.minecraft.world.Heightmap;
|
import net.minecraft.world.Heightmap;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
@ -35,6 +35,7 @@ import ru.betterend.blocks.RunedFlavolite;
|
||||||
import ru.betterend.blocks.entities.EternalPedestalEntity;
|
import ru.betterend.blocks.entities.EternalPedestalEntity;
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
import ru.betterend.registry.EndFeatures;
|
import ru.betterend.registry.EndFeatures;
|
||||||
|
import ru.betterend.registry.EndPortals;
|
||||||
|
|
||||||
public class EternalRitual {
|
public class EternalRitual {
|
||||||
private final static Set<Point> STRUCTURE_MAP = Sets.newHashSet(
|
private final static Set<Point> STRUCTURE_MAP = Sets.newHashSet(
|
||||||
|
@ -97,13 +98,24 @@ public class EternalRitual {
|
||||||
moveY = Direction.EAST;
|
moveY = Direction.EAST;
|
||||||
}
|
}
|
||||||
boolean valid = this.checkFrame();
|
boolean valid = this.checkFrame();
|
||||||
|
Item item = null;
|
||||||
for (Point pos : STRUCTURE_MAP) {
|
for (Point pos : STRUCTURE_MAP) {
|
||||||
BlockPos.Mutable checkPos = center.mutableCopy();
|
BlockPos.Mutable checkPos = center.mutableCopy();
|
||||||
checkPos.move(moveX, pos.x).move(moveY, pos.y);
|
checkPos.move(moveX, pos.x).move(moveY, pos.y);
|
||||||
valid &= this.isActive(checkPos);
|
valid &= this.isActive(checkPos);
|
||||||
}
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.activatePortal();
|
EternalPedestalEntity pedestal = (EternalPedestalEntity) world.getBlockEntity(checkPos);
|
||||||
|
Item pItem = pedestal.getStack(0).getItem();
|
||||||
|
if (item == null) {
|
||||||
|
item = pItem;
|
||||||
|
}
|
||||||
|
else if (!item.equals(pItem)) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (valid && item != null) {
|
||||||
|
this.activatePortal(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,20 +138,21 @@ public class EternalRitual {
|
||||||
return this.active;
|
return this.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void activatePortal() {
|
private void activatePortal(Item item) {
|
||||||
if (active) return;
|
if (active) return;
|
||||||
this.activatePortal(world, center);
|
int state = EndPortals.getPortalState(Registry.ITEM.getId(item));
|
||||||
|
this.activatePortal(world, center, state);
|
||||||
this.doEffects((ServerWorld) world, center);
|
this.doEffects((ServerWorld) world, center);
|
||||||
if (exit == null) {
|
if (exit == null) {
|
||||||
this.exit = this.findPortalPos();
|
this.exit = this.findPortalPos(state);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
World targetWorld = this.getTargetWorld();
|
World targetWorld = this.getTargetWorld(state);
|
||||||
if (targetWorld.getBlockState(exit.up()).isOf(EndBlocks.END_PORTAL_BLOCK)) {
|
if (targetWorld.getBlockState(exit.up()).isOf(EndBlocks.END_PORTAL_BLOCK)) {
|
||||||
this.exit = this.findPortalPos();
|
this.exit = this.findPortalPos(state);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.activatePortal(targetWorld, exit);
|
this.activatePortal(targetWorld, exit, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.active = true;
|
this.active = true;
|
||||||
|
@ -164,7 +177,7 @@ public class EternalRitual {
|
||||||
serverWorld.playSound(null, center, SoundEvents.BLOCK_END_PORTAL_SPAWN, SoundCategory.NEUTRAL, 16, 1);
|
serverWorld.playSound(null, center, SoundEvents.BLOCK_END_PORTAL_SPAWN, SoundCategory.NEUTRAL, 16, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void activatePortal(World world, BlockPos center) {
|
private void activatePortal(World world, BlockPos center, int dim) {
|
||||||
BlockPos framePos = center.down();
|
BlockPos framePos = center.down();
|
||||||
Direction moveDir = Direction.Axis.X == axis ? Direction.NORTH : Direction.EAST;
|
Direction moveDir = Direction.Axis.X == axis ? Direction.NORTH : Direction.EAST;
|
||||||
BlockState frame = FRAME.getDefaultState().with(ACTIVE, true);
|
BlockState frame = FRAME.getDefaultState().with(ACTIVE, true);
|
||||||
|
@ -181,7 +194,7 @@ public class EternalRitual {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Direction.Axis portalAxis = Direction.Axis.X == axis ? Direction.Axis.Z : Direction.Axis.X;
|
Direction.Axis portalAxis = Direction.Axis.X == axis ? Direction.Axis.Z : Direction.Axis.X;
|
||||||
BlockState portal = PORTAL.getDefaultState().with(EndPortalBlock.AXIS, portalAxis);
|
BlockState portal = PORTAL.getDefaultState().with(EndPortalBlock.AXIS, portalAxis).with(EndPortalBlock.PORTAL, dim);
|
||||||
ParticleEffect effect = new BlockStateParticleEffect(ParticleTypes.BLOCK, portal);
|
ParticleEffect effect = new BlockStateParticleEffect(ParticleTypes.BLOCK, portal);
|
||||||
ServerWorld serverWorld = (ServerWorld) world;
|
ServerWorld serverWorld = (ServerWorld) world;
|
||||||
|
|
||||||
|
@ -201,9 +214,9 @@ public class EternalRitual {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePortal() {
|
public void removePortal(int state) {
|
||||||
if (!active || isInvalid()) return;
|
if (!active || isInvalid()) return;
|
||||||
World targetWorld = this.getTargetWorld();
|
World targetWorld = this.getTargetWorld(state);
|
||||||
this.removePortal(world, center);
|
this.removePortal(world, center);
|
||||||
this.removePortal(targetWorld, exit);
|
this.removePortal(targetWorld, exit);
|
||||||
}
|
}
|
||||||
|
@ -236,10 +249,10 @@ public class EternalRitual {
|
||||||
this.active = false;
|
this.active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockPos findPortalPos() {
|
private BlockPos findPortalPos(int state) {
|
||||||
MinecraftServer server = world.getServer();
|
MinecraftServer server = world.getServer();
|
||||||
assert server != null;
|
assert server != null;
|
||||||
ServerWorld targetWorld = (ServerWorld) this.getTargetWorld();
|
ServerWorld targetWorld = (ServerWorld) this.getTargetWorld(state);
|
||||||
Registry<DimensionType> registry = server.getRegistryManager().getDimensionTypes();
|
Registry<DimensionType> registry = server.getRegistryManager().getDimensionTypes();
|
||||||
double mult = Objects.requireNonNull(registry.get(DimensionType.THE_END_ID)).getCoordinateScale();
|
double mult = Objects.requireNonNull(registry.get(DimensionType.THE_END_ID)).getCoordinateScale();
|
||||||
BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / mult, center.getY(), center.getZ() / mult);
|
BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / mult, center.getY(), center.getZ() / mult);
|
||||||
|
@ -281,9 +294,11 @@ public class EternalRitual {
|
||||||
return basePos.toImmutable();
|
return basePos.toImmutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private World getTargetWorld() {
|
private World getTargetWorld(int state) {
|
||||||
RegistryKey<World> target = world.getRegistryKey() == World.END ? World.OVERWORLD : World.END;
|
if (world.getRegistryKey() == World.END) {
|
||||||
return Objects.requireNonNull(world.getServer()).getWorld(target);
|
return EndPortals.getWorld(world.getServer(), state);
|
||||||
|
}
|
||||||
|
return Objects.requireNonNull(world.getServer()).getWorld(World.END);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkIsAreaValid(World world, BlockPos pos, Direction.Axis axis) {
|
private boolean checkIsAreaValid(World world, BlockPos pos, Direction.Axis axis) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue