Portal property (WIP)
This commit is contained in:
parent
ee4c4aed73
commit
269821dee8
4 changed files with 55 additions and 5 deletions
|
@ -42,6 +42,7 @@ public class BetterEnd implements ModInitializer {
|
|||
public static final Logger LOGGER = Logger.get();
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
EndPortals.loadPortals();
|
||||
EndSounds.register();
|
||||
EndItems.register();
|
||||
EndBlocks.register();
|
||||
|
@ -64,7 +65,6 @@ public class BetterEnd implements ModInitializer {
|
|||
Integrations.register();
|
||||
BonemealUtil.init();
|
||||
GeneratorOptions.init();
|
||||
EndPortals.loadPortals();
|
||||
|
||||
if (hasGuideBook()) {
|
||||
GuideBookItem.register();
|
||||
|
|
|
@ -4,6 +4,7 @@ import net.minecraft.state.property.BooleanProperty;
|
|||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.util.StringIdentifiable;
|
||||
import ru.betterend.registry.EndPortals;
|
||||
|
||||
public class BlockProperties {
|
||||
public static final EnumProperty<HydraluxShape> HYDRALUX_SHAPE = EnumProperty.of("shape", HydraluxShape.class);
|
||||
|
@ -21,6 +22,7 @@ public class BlockProperties {
|
|||
public static final IntProperty ROTATION = IntProperty.of("rotation", 0, 3);
|
||||
public static final IntProperty FULLNESS = IntProperty.of("fullness", 0, 3);
|
||||
public static final IntProperty COLOR = IntProperty.of("color", 0, 7);
|
||||
public static final IntProperty PORTAL = IntProperty.of("portal", 0, EndPortals.getCount());
|
||||
|
||||
public static enum TripleShape implements StringIdentifiable {
|
||||
TOP("top"),
|
||||
|
|
|
@ -6,14 +6,20 @@ import java.util.Random;
|
|||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.NetherPortalBlock;
|
||||
import net.minecraft.client.color.block.BlockColorProvider;
|
||||
import net.minecraft.client.color.item.ItemColorProvider;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.util.BlockRotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
@ -26,15 +32,25 @@ import net.minecraft.world.WorldAccess;
|
|||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import ru.betterend.client.render.ERenderLayer;
|
||||
import ru.betterend.interfaces.IColorProvider;
|
||||
import ru.betterend.interfaces.IRenderTypeable;
|
||||
import ru.betterend.interfaces.TeleportingEntity;
|
||||
import ru.betterend.registry.EndParticles;
|
||||
import ru.betterend.registry.EndPortals;
|
||||
|
||||
public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable, IColorProvider {
|
||||
public static final IntProperty PORTAL = BlockProperties.PORTAL;
|
||||
|
||||
public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable {
|
||||
public EndPortalBlock() {
|
||||
super(FabricBlockSettings.copyOf(Blocks.NETHER_PORTAL).resistance(Blocks.BEDROCK.getBlastResistance()).luminance(state -> 12));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(PORTAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
|
||||
|
@ -68,7 +84,8 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
|
|||
if (world instanceof ServerWorld && !entity.hasVehicle() && !entity.hasPassengers() && entity.canUsePortals()) {
|
||||
if (entity.hasNetherPortalCooldown()) return;
|
||||
boolean isOverworld = world.getRegistryKey().equals(World.OVERWORLD);
|
||||
ServerWorld destination = ((ServerWorld) world).getServer().getWorld(isOverworld ? World.END : World.OVERWORLD);
|
||||
MinecraftServer server = ((ServerWorld) world).getServer();
|
||||
ServerWorld destination = isOverworld ? server.getWorld(World.END) : EndPortals.getWorld(server, state.get(PORTAL));
|
||||
BlockPos exitPos = this.findExitPos(destination, pos, entity);
|
||||
if (exitPos == null) return;
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
|
@ -174,4 +191,18 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
|
|||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockColorProvider getProvider() {
|
||||
return (state, world, pos, tintIndex) -> {
|
||||
return EndPortals.getColor(state.get(PORTAL));
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemColorProvider getItemProvider() {
|
||||
return (stack, tintIndex) -> {
|
||||
return EndPortals.getColor(0);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.google.gson.JsonObject;
|
|||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.config.ConfigWriter;
|
||||
import ru.betterend.util.JsonFactory;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
@ -40,6 +41,10 @@ public class EndPortals {
|
|||
}
|
||||
}
|
||||
|
||||
public static int getCount() {
|
||||
return MHelper.max(portals.length - 1, 1);
|
||||
}
|
||||
|
||||
public static ServerWorld getWorld(MinecraftServer server, int state) {
|
||||
if (state >= portals.length) {
|
||||
return server.getOverworld();
|
||||
|
@ -47,6 +52,15 @@ public class EndPortals {
|
|||
return portals[state].getWorld(server);
|
||||
}
|
||||
|
||||
public static int getPortalState(Identifier item) {
|
||||
for (int i = 0; i < portals.length; i++) {
|
||||
if (portals[i].item.equals(item)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int getColor(int state) {
|
||||
return portals[state].color;
|
||||
}
|
||||
|
@ -62,25 +76,28 @@ public class EndPortals {
|
|||
}
|
||||
|
||||
private static PortalInfo makeDefault() {
|
||||
return new PortalInfo(new Identifier("minecraft:overworld"), 255, 255, 255);
|
||||
return new PortalInfo(new Identifier("minecraft:overworld"), BetterEnd.makeID("eternal_crystal"), 255, 255, 255);
|
||||
}
|
||||
|
||||
private static class PortalInfo {
|
||||
private final Identifier dimension;
|
||||
private final Identifier item;
|
||||
private final int color;
|
||||
private ServerWorld world;
|
||||
|
||||
PortalInfo(JsonObject obj) {
|
||||
this(
|
||||
new Identifier(JsonFactory.getString(obj, "dimension", "minecraft:overworld")),
|
||||
new Identifier(JsonFactory.getString(obj, "item", "betterend:eternal_crystal")),
|
||||
JsonFactory.getInt(obj, "colorRed", 255),
|
||||
JsonFactory.getInt(obj, "colorGreen", 255),
|
||||
JsonFactory.getInt(obj, "colorBlue", 255)
|
||||
);
|
||||
}
|
||||
|
||||
PortalInfo(Identifier dimension, int r, int g, int b) {
|
||||
PortalInfo(Identifier dimension, Identifier item, int r, int g, int b) {
|
||||
this.dimension = dimension;
|
||||
this.item = item;
|
||||
this.color = MHelper.color(r, g, b);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue