mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-28 19:39:11 +00:00
局部修改
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.momirealms.craftengine.core.block.behavior.AbstractBlockBehavior;
|
||||
import net.momirealms.craftengine.core.block.behavior.EmptyBlockBehavior;
|
||||
import net.momirealms.craftengine.core.block.parser.BlockNbtParser;
|
||||
import net.momirealms.craftengine.core.block.properties.Property;
|
||||
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
|
||||
import net.momirealms.craftengine.core.loot.LootTable;
|
||||
@@ -37,7 +38,7 @@ public abstract class AbstractCustomBlock implements CustomBlock {
|
||||
@NotNull Holder.Reference<CustomBlock> holder,
|
||||
@NotNull Map<String, Property<?>> properties,
|
||||
@NotNull Map<String, Integer> appearances,
|
||||
@NotNull Map<String, VariantState> variantMapper,
|
||||
@NotNull Map<String, BlockStateVariant> variantMapper,
|
||||
@NotNull BlockSettings settings,
|
||||
@NotNull Map<EventTrigger, List<Function<PlayerOptionalContext>>> events,
|
||||
@NotNull List<Map<String, Object>> behaviorConfig,
|
||||
@@ -57,14 +58,14 @@ public abstract class AbstractCustomBlock implements CustomBlock {
|
||||
placements.add(Property.createStateForPlacement(propertyEntry.getKey(), propertyEntry.getValue()));
|
||||
}
|
||||
this.placementFunction = composite(placements);
|
||||
for (Map.Entry<String, VariantState> entry : variantMapper.entrySet()) {
|
||||
for (Map.Entry<String, BlockStateVariant> entry : variantMapper.entrySet()) {
|
||||
String nbtString = entry.getKey();
|
||||
CompoundTag tag = BlockNbtParser.deserialize(this, nbtString);
|
||||
if (tag == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.block.state.property.invalid_format", nbtString);
|
||||
}
|
||||
VariantState variantState = entry.getValue();
|
||||
int vanillaStateRegistryId = appearances.getOrDefault(variantState.appearance(), -1);
|
||||
BlockStateVariant blockStateVariant = entry.getValue();
|
||||
int vanillaStateRegistryId = appearances.getOrDefault(blockStateVariant.appearance(), -1);
|
||||
// This should never happen
|
||||
if (vanillaStateRegistryId == -1) {
|
||||
vanillaStateRegistryId = appearances.values().iterator().next();
|
||||
@@ -72,9 +73,9 @@ public abstract class AbstractCustomBlock implements CustomBlock {
|
||||
// Late init states
|
||||
for (ImmutableBlockState state : this.getPossibleStates(tag)) {
|
||||
state.setBehavior(this.behavior);
|
||||
state.setSettings(variantState.settings());
|
||||
state.setSettings(blockStateVariant.settings());
|
||||
state.setVanillaBlockState(BlockRegistryMirror.stateByRegistryId(vanillaStateRegistryId));
|
||||
state.setCustomBlockState(BlockRegistryMirror.stateByRegistryId(variantState.internalRegistryId()));
|
||||
state.setCustomBlockState(BlockRegistryMirror.stateByRegistryId(blockStateVariant.internalRegistryId()));
|
||||
}
|
||||
}
|
||||
// double check if there's any invalid state
|
||||
@@ -189,10 +190,7 @@ public abstract class AbstractCustomBlock implements CustomBlock {
|
||||
@Override
|
||||
public ImmutableBlockState getStateForPlacement(BlockPlaceContext context) {
|
||||
ImmutableBlockState state = this.placementFunction.apply(context, defaultState());
|
||||
if (this.behavior instanceof AbstractBlockBehavior blockBehavior) {
|
||||
state = blockBehavior.updateStateForPlacement(context, state);
|
||||
}
|
||||
return state;
|
||||
return this.behavior.updateStateForPlacement(context, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
import net.momirealms.craftengine.core.util.ObjectHolder;
|
||||
|
||||
public interface BehaviorHolder {
|
||||
|
||||
ObjectHolder<BlockBehavior> getBehaviorHolder();
|
||||
}
|
||||
@@ -12,6 +12,6 @@ public class BlockEntityState {
|
||||
}
|
||||
|
||||
public CompoundTag nbt() {
|
||||
return nbt;
|
||||
return this.nbt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package net.momirealms.craftengine.core.block;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public class BlockKeys {
|
||||
public final class BlockKeys {
|
||||
private BlockKeys() {}
|
||||
|
||||
public static final Key NOTE_BLOCK = Key.of("minecraft:note_block");
|
||||
public static final Key TRIPWIRE = Key.of("minecraft:tripwire");
|
||||
public static final Key CRAFTING_TABLE = Key.of("minecraft:crafting_table");
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
public final class BlockRegistryMirror {
|
||||
private static BlockStateWrapper[] customBlockStates;
|
||||
private static BlockStateWrapper[] blockStates;
|
||||
private static BlockStateWrapper stoneState;
|
||||
|
||||
public static void init(BlockStateWrapper[] states, BlockStateWrapper state) {
|
||||
customBlockStates = states;
|
||||
if (blockStates != null) throw new IllegalStateException("block states are already set");
|
||||
blockStates = states;
|
||||
stoneState = state;
|
||||
}
|
||||
|
||||
public static BlockStateWrapper stateByRegistryId(int vanillaId) {
|
||||
if (vanillaId < 0) return stoneState;
|
||||
return customBlockStates[vanillaId];
|
||||
return blockStates[vanillaId];
|
||||
}
|
||||
|
||||
public static int size() {
|
||||
return customBlockStates.length;
|
||||
return blockStates.length;
|
||||
}
|
||||
|
||||
public static BlockStateWrapper stoneState() {
|
||||
|
||||
@@ -355,10 +355,12 @@ public class BlockSettings {
|
||||
return this;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Modifier {
|
||||
|
||||
void apply(BlockSettings settings);
|
||||
|
||||
@FunctionalInterface
|
||||
interface Factory {
|
||||
|
||||
Modifier createModifier(Object value);
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.momirealms.craftengine.core.block;
|
||||
|
||||
public interface BlockShape {
|
||||
|
||||
Object getShape(Object thisObj, Object[] args) throws Exception;
|
||||
Object getShape(Object thisObj, Object[] args);
|
||||
|
||||
Object getCollisionShape(Object thisObj, Object[] args);
|
||||
|
||||
|
||||
@@ -5,13 +5,15 @@ import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BlockSounds {
|
||||
public final class BlockSounds {
|
||||
/*
|
||||
Fall 0.5 0.75
|
||||
Place 1, 0.8
|
||||
Step 0.15, 1
|
||||
Place 1 0.8
|
||||
Step 0.15 1
|
||||
Hit 0.5 0.5
|
||||
Break 1 0.8
|
||||
Land 0.3 1
|
||||
Destroy 1 1
|
||||
*/
|
||||
public static final SoundData EMPTY_SOUND = new SoundData(Key.of("minecraft:intentionally_empty"), SoundData.SoundValue.FIXED_1, SoundData.SoundValue.FIXED_1);
|
||||
public static final BlockSounds EMPTY = new BlockSounds(EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND, EMPTY_SOUND);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
public class BlockStateArrangeException extends RuntimeException {
|
||||
public BlockStateArrangeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
import net.momirealms.craftengine.core.block.properties.Property;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.Pair;
|
||||
import net.momirealms.craftengine.core.util.StringReader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BlockStateMatcher {
|
||||
private final List<Pair<Property<?>, Comparable<?>>> properties;
|
||||
private final Key id;
|
||||
|
||||
public BlockStateMatcher(Key id, List<Pair<Property<?>, Comparable<?>>> properties) {
|
||||
this.properties = properties;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean matches(ImmutableBlockState state) {
|
||||
if (!state.owner().value().id().equals(this.id)) {
|
||||
return false;
|
||||
}
|
||||
for (Pair<Property<?>, Comparable<?>> pair : this.properties) {
|
||||
if (!state.get(pair.left()).equals(pair.right())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (properties.isEmpty()) {
|
||||
return id.toString();
|
||||
}
|
||||
return id + "[" + getPropertiesAsString() + "]";
|
||||
}
|
||||
|
||||
public String getPropertiesAsString() {
|
||||
return properties.stream()
|
||||
.map(entry -> {
|
||||
Property<?> property = entry.left();
|
||||
return property.name() + "=" + Property.formatValue(property, entry.right());
|
||||
})
|
||||
.collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Nullable
|
||||
public static BlockStateMatcher deserialize(@NotNull String data) {
|
||||
StringReader reader = StringReader.simple(data);
|
||||
String blockIdString = reader.readUnquotedString();
|
||||
if (reader.canRead() && reader.peek() == ':') {
|
||||
reader.skip();
|
||||
blockIdString = blockIdString + ":" + reader.readUnquotedString();
|
||||
}
|
||||
Optional<Holder.Reference<CustomBlock>> optional = BuiltInRegistries.BLOCK.get(Key.from(blockIdString));
|
||||
if (optional.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Holder<CustomBlock> holder = optional.get();
|
||||
List<Pair<Property<?>, Comparable<?>>> properties = new ArrayList<>();
|
||||
if (reader.canRead() && reader.peek() == '[') {
|
||||
reader.skip();
|
||||
while (reader.canRead()) {
|
||||
reader.skipWhitespace();
|
||||
if (reader.peek() == ']') break;
|
||||
String propertyName = reader.readUnquotedString();
|
||||
reader.skipWhitespace();
|
||||
if (!reader.canRead() || reader.peek() != '=') {
|
||||
return null;
|
||||
}
|
||||
reader.skip();
|
||||
reader.skipWhitespace();
|
||||
String propertyValue = reader.readUnquotedString();
|
||||
Property<?> property = holder.value().getProperty(propertyName);
|
||||
if (property != null) {
|
||||
Optional<?> optionalValue = property.optional(propertyValue);
|
||||
if (optionalValue.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
properties.add(Pair.of(property, (Comparable<?>) optionalValue.get()));
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
reader.skipWhitespace();
|
||||
if (reader.canRead() && reader.peek() == ',') {
|
||||
reader.skip();
|
||||
}
|
||||
}
|
||||
reader.skipWhitespace();
|
||||
if (reader.canRead() && reader.peek() == ']') {
|
||||
reader.skip();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return new BlockStateMatcher(holder.value().id(), properties);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
public class VariantState {
|
||||
public class BlockStateVariant {
|
||||
private final String appearance;
|
||||
private final BlockSettings settings;
|
||||
private final int internalId;
|
||||
|
||||
public VariantState(String appearance, BlockSettings settings, int internalId) {
|
||||
public BlockStateVariant(String appearance, BlockSettings settings, int internalId) {
|
||||
this.appearance = appearance;
|
||||
this.settings = settings;
|
||||
this.internalId = internalId;
|
||||
@@ -18,7 +18,7 @@ import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BlockStateVariantProvider {
|
||||
public final class BlockStateVariantProvider {
|
||||
private final ImmutableSortedMap<String, Property<?>> properties;
|
||||
private final ImmutableList<ImmutableBlockState> states;
|
||||
private final Holder<CustomBlock> owner;
|
||||
@@ -65,7 +65,7 @@ public class BlockStateVariantProvider {
|
||||
|
||||
@NotNull
|
||||
public ImmutableBlockState getDefaultState() {
|
||||
ImmutableBlockState first = this.states.get(0);
|
||||
ImmutableBlockState first = this.states.getFirst();
|
||||
for (Property<?> property : this.properties.values()) {
|
||||
first = ImmutableBlockState.with(first, property, property.defaultValue());
|
||||
}
|
||||
@@ -73,11 +73,11 @@ public class BlockStateVariantProvider {
|
||||
}
|
||||
|
||||
public ImmutableList<ImmutableBlockState> states() {
|
||||
return states;
|
||||
return this.states;
|
||||
}
|
||||
|
||||
public Holder<CustomBlock> owner() {
|
||||
return owner;
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -59,6 +59,11 @@ public interface BlockStateWrapper {
|
||||
super(handle, registryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DelegatingBlockState handle() {
|
||||
return (DelegatingBlockState) super.handle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanillaBlock() {
|
||||
return false;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
public interface ChainUpdateBlockIndicator {
|
||||
|
||||
boolean isNoteBlock();
|
||||
|
||||
boolean isTripwire();
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
public interface CraftEngineNMSBlock extends ShapeHolder, BehaviorHolder, ChainUpdateBlockIndicator {
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public interface CustomBlock {
|
||||
|
||||
Builder settings(BlockSettings settings);
|
||||
|
||||
Builder variantMapper(Map<String, VariantState> variantMapper);
|
||||
Builder variantMapper(Map<String, BlockStateVariant> variantMapper);
|
||||
|
||||
@NotNull CustomBlock build();
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
public interface CustomBlockStateHolder {
|
||||
|
||||
ImmutableBlockState customBlockState();
|
||||
|
||||
void setCustomBlockState(ImmutableBlockState state);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
import net.momirealms.craftengine.core.util.ObjectHolder;
|
||||
|
||||
/**
|
||||
* Interface representing a delegatable block that can dynamically modify its shape and behavior at runtime.
|
||||
* Implementations of this interface serve as actual block instances injected into Minecraft's
|
||||
* {@code BuiltInRegistries.BLOCK}, enabling real-time modifications to physical properties and geometry.
|
||||
*
|
||||
* <p>Utilizes the {@code ObjectHolder} pattern to delegate block characteristics, allowing runtime updates
|
||||
* to collision boxes and interaction logic without reconstructing block instances.</p>
|
||||
*/
|
||||
public interface DelegatingBlock {
|
||||
|
||||
/**
|
||||
* Gets the mutable holder for the block's shape delegate.
|
||||
* Modifying the contained {@code BlockShape} will dynamically update
|
||||
* collision bounding boxes and supporting shape.
|
||||
*
|
||||
* @return Non-null object holder containing current block shape
|
||||
*/
|
||||
ObjectHolder<BlockShape> shapeDelegate();
|
||||
|
||||
/**
|
||||
* Gets the mutable holder for the block's behavior delegate.
|
||||
* Modifying the contained {@code BlockBehavior} will dynamically adjust:
|
||||
* - Physics properties
|
||||
* - Interaction logic (e.g. click responses)
|
||||
* - State update rules
|
||||
*
|
||||
* @return Non-null object holder containing current block behavior
|
||||
*/
|
||||
ObjectHolder<BlockBehavior> behaviorDelegate();
|
||||
|
||||
@Deprecated
|
||||
boolean isNoteBlock();
|
||||
|
||||
@Deprecated
|
||||
boolean isTripwire();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Interface representing a block state that can delegate its underlying immutable state.
|
||||
*
|
||||
* @see ImmutableBlockState The immutable state container being delegated
|
||||
*/
|
||||
public interface DelegatingBlockState {
|
||||
|
||||
/**
|
||||
* Gets the current immutable block state being delegated.
|
||||
*
|
||||
* @return The current immutable block state instance
|
||||
*/
|
||||
@Nullable
|
||||
ImmutableBlockState blockState();
|
||||
|
||||
/**
|
||||
* Replaces the currently delegated block state with a new immutable state.
|
||||
*
|
||||
* @param state The new immutable state to delegate to
|
||||
*/
|
||||
void setBlockState(@Nullable ImmutableBlockState state);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import net.momirealms.craftengine.core.util.Key;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class EmptyBlock extends AbstractCustomBlock {
|
||||
public final class EmptyBlock extends AbstractCustomBlock {
|
||||
public static EmptyBlock INSTANCE;
|
||||
public static ImmutableBlockState STATE;
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
public class EmptyBlockBehavior extends BlockBehavior {
|
||||
public static final EmptyBlockBehavior INSTANCE = new EmptyBlockBehavior();
|
||||
|
||||
@Override
|
||||
public CustomBlock block() {
|
||||
return EmptyBlock.INSTANCE;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ImmutableBlockState extends BlockStateHolder {
|
||||
public final class ImmutableBlockState extends BlockStateHolder {
|
||||
private CompoundTag tag;
|
||||
private BlockStateWrapper customBlockState;
|
||||
private BlockStateWrapper vanillaBlockState;
|
||||
@@ -26,7 +26,7 @@ public class ImmutableBlockState extends BlockStateHolder {
|
||||
private Integer hashCode;
|
||||
private BlockSettings settings;
|
||||
|
||||
protected ImmutableBlockState(
|
||||
ImmutableBlockState(
|
||||
Holder<CustomBlock> owner,
|
||||
Reference2ObjectArrayMap<Property<?>, Comparable<?>> propertyMap
|
||||
) {
|
||||
@@ -54,7 +54,7 @@ public class ImmutableBlockState extends BlockStateHolder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ImmutableBlockState state)) return false;
|
||||
return state.owner == this.owner && state.tag.equals(this.tag);
|
||||
@@ -62,22 +62,10 @@ public class ImmutableBlockState extends BlockStateHolder {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (hashCode == null) {
|
||||
hashCode = getNbtToSave().hashCode();
|
||||
if (this.hashCode == null) {
|
||||
this.hashCode = getNbtToSave().hashCode();
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public BlockSounds sounds() {
|
||||
return settings.sounds;
|
||||
}
|
||||
|
||||
public int luminance() {
|
||||
return settings.luminance;
|
||||
}
|
||||
|
||||
public PushReaction pushReaction() {
|
||||
return settings.pushReaction;
|
||||
return this.hashCode;
|
||||
}
|
||||
|
||||
public BlockStateWrapper customBlockState() {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class InactiveCustomBlock extends AbstractCustomBlock {
|
||||
public final class InactiveCustomBlock extends AbstractCustomBlock {
|
||||
private final Map<CompoundTag, ImmutableBlockState> cachedData = new HashMap<>();
|
||||
|
||||
public InactiveCustomBlock(Key id, Holder.Reference<CustomBlock> holder) {
|
||||
@@ -23,7 +23,7 @@ public class InactiveCustomBlock extends AbstractCustomBlock {
|
||||
@Override
|
||||
public ImmutableBlockState getBlockState(CompoundTag nbt) {
|
||||
return this.cachedData.computeIfAbsent(nbt, k -> {
|
||||
ImmutableBlockState state = new ImmutableBlockState(holder, new Reference2ObjectArrayMap<>());
|
||||
ImmutableBlockState state = new ImmutableBlockState(super.holder, new Reference2ObjectArrayMap<>());
|
||||
state.setNbtToSave(state.toNbtToSave(nbt));
|
||||
return state;
|
||||
});
|
||||
|
||||
@@ -2,11 +2,11 @@ package net.momirealms.craftengine.core.block;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
|
||||
public class DelayedInitBlockState {
|
||||
public final class LazyBlockState {
|
||||
private final String state;
|
||||
private BlockStateWrapper packedBlockState;
|
||||
|
||||
public DelayedInitBlockState(String state) {
|
||||
public LazyBlockState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
import net.momirealms.craftengine.core.util.ObjectHolder;
|
||||
|
||||
public interface ShapeHolder {
|
||||
|
||||
ObjectHolder<BlockShape> getShapeHolder();
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UnsafeBlockStateMatcher {
|
||||
public final class UnsafeBlockStateMatcher {
|
||||
private final List<Pair<String, String>> matchers;
|
||||
private final Key id;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
public class UpdateOption {
|
||||
public final class UpdateOption {
|
||||
public static final UpdateOption UPDATE_ALL = new UpdateOption(3);
|
||||
public static final UpdateOption UPDATE_NONE = new UpdateOption(4);
|
||||
public static final UpdateOption UPDATE_ALL_IMMEDIATE = new UpdateOption(11);
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public class VanillaBlockState {
|
||||
private final Key type;
|
||||
private final String properties;
|
||||
private final int registryId;
|
||||
|
||||
public VanillaBlockState(Key type, String properties, int registryId) {
|
||||
this.properties = properties;
|
||||
this.registryId = registryId;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String properties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public int registryId() {
|
||||
return registryId;
|
||||
}
|
||||
|
||||
public Key type() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.block.behavior;
|
||||
|
||||
import net.momirealms.craftengine.core.block.BlockBehavior;
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.EmptyBlockBehavior;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.momirealms.craftengine.core.block.behavior;
|
||||
|
||||
import net.momirealms.craftengine.core.block.BlockBehavior;
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.EmptyBlock;
|
||||
|
||||
public final class EmptyBlockBehavior extends BlockBehavior {
|
||||
public static final EmptyBlockBehavior INSTANCE = new EmptyBlockBehavior();
|
||||
|
||||
@Override
|
||||
public CustomBlock block() {
|
||||
return EmptyBlock.INSTANCE;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
package net.momirealms.craftengine.core.block.parser;
|
||||
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.properties.Property;
|
||||
import net.momirealms.craftengine.core.util.StringReader;
|
||||
import net.momirealms.sparrow.nbt.CompoundTag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BlockNbtParser {
|
||||
|
||||
public final class BlockNbtParser {
|
||||
private BlockNbtParser() {}
|
||||
|
||||
@Nullable
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
package net.momirealms.craftengine.core.block.parser;
|
||||
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.block.properties.Property;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
@@ -13,7 +15,7 @@ import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockStateParser {
|
||||
public final class BlockStateParser {
|
||||
private static final char START = '[';
|
||||
private static final char EQUAL = '=';
|
||||
private static final char SEPARATOR = ',';
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.function;
|
||||
|
||||
import net.momirealms.craftengine.core.block.DelayedInitBlockState;
|
||||
import net.momirealms.craftengine.core.block.LazyBlockState;
|
||||
import net.momirealms.craftengine.core.item.DelayedInitItem;
|
||||
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
@@ -26,7 +26,7 @@ public class ParticleFunction<CTX extends Context> extends AbstractConditionalFu
|
||||
|
||||
static {
|
||||
registerParticleData(map -> new BlockStateData(
|
||||
new DelayedInitBlockState(ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("block-state"), "warning.config.function.particle.missing_block_state"))),
|
||||
new LazyBlockState(ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("block-state"), "warning.config.function.particle.missing_block_state"))),
|
||||
ParticleTypes.BLOCK, ParticleTypes.FALLING_DUST, ParticleTypes.DUST_PILLAR, ParticleTypes.BLOCK_CRUMBLE, ParticleTypes.BLOCK_MARKER);
|
||||
registerParticleData(map -> new ColorData(
|
||||
Color.fromString(ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("color"), "warning.config.function.particle.missing_color").split(","))),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.function;
|
||||
|
||||
import net.momirealms.craftengine.core.block.DelayedInitBlockState;
|
||||
import net.momirealms.craftengine.core.block.LazyBlockState;
|
||||
import net.momirealms.craftengine.core.block.UpdateOption;
|
||||
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
@@ -18,15 +18,15 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PlaceBlockFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
|
||||
private final DelayedInitBlockState delayedInitBlockState;
|
||||
private final LazyBlockState lazyBlockState;
|
||||
private final NumberProvider x;
|
||||
private final NumberProvider y;
|
||||
private final NumberProvider z;
|
||||
private final NumberProvider updateFlags;
|
||||
|
||||
public PlaceBlockFunction(DelayedInitBlockState delayedInitBlockState, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider updateFlags, List<Condition<CTX>> predicates) {
|
||||
public PlaceBlockFunction(LazyBlockState lazyBlockState, NumberProvider x, NumberProvider y, NumberProvider z, NumberProvider updateFlags, List<Condition<CTX>> predicates) {
|
||||
super(predicates);
|
||||
this.delayedInitBlockState = delayedInitBlockState;
|
||||
this.lazyBlockState = lazyBlockState;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
@@ -38,7 +38,7 @@ public class PlaceBlockFunction<CTX extends Context> extends AbstractConditional
|
||||
Optional<WorldPosition> optionalWorldPosition = ctx.getOptionalParameter(DirectContextParameters.POSITION);
|
||||
if (optionalWorldPosition.isPresent()) {
|
||||
World world = optionalWorldPosition.get().world();
|
||||
world.setBlockAt(MCUtils.fastFloor(this.x.getDouble(ctx)), MCUtils.fastFloor(this.y.getDouble(ctx)), MCUtils.fastFloor(this.z.getDouble(ctx)), this.delayedInitBlockState.getState(), this.updateFlags.getInt(ctx));
|
||||
world.setBlockAt(MCUtils.fastFloor(this.x.getDouble(ctx)), MCUtils.fastFloor(this.y.getDouble(ctx)), MCUtils.fastFloor(this.z.getDouble(ctx)), this.lazyBlockState.getState(), this.updateFlags.getInt(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,12 +56,12 @@ public class PlaceBlockFunction<CTX extends Context> extends AbstractConditional
|
||||
@Override
|
||||
public Function<CTX> create(Map<String, Object> arguments) {
|
||||
String state = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("block-state"), "warning.config.function.place_block.missing_block_state");
|
||||
DelayedInitBlockState delayedInitBlockState = new DelayedInitBlockState(state);
|
||||
LazyBlockState lazyBlockState = new LazyBlockState(state);
|
||||
NumberProvider x = NumberProviders.fromObject(arguments.getOrDefault("x", "<arg:position.x>"));
|
||||
NumberProvider y = NumberProviders.fromObject(arguments.getOrDefault("y", "<arg:position.y>"));
|
||||
NumberProvider z = NumberProviders.fromObject(arguments.getOrDefault("z", "<arg:position.z>"));
|
||||
NumberProvider flags = Optional.ofNullable(arguments.get("update-flags")).map(NumberProviders::fromObject).orElse(NumberProviders.direct(UpdateOption.UPDATE_ALL.flags()));
|
||||
return new PlaceBlockFunction<>(delayedInitBlockState, x, y, z, flags, getPredicates(arguments));
|
||||
return new PlaceBlockFunction<>(lazyBlockState, x, y, z, flags, getPredicates(arguments));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.momirealms.craftengine.core.plugin.locale;
|
||||
|
||||
import net.momirealms.craftengine.core.block.BlockStateParser;
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.block.parser.BlockStateParser;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.momirealms.craftengine.core.world.particle;
|
||||
|
||||
import net.momirealms.craftengine.core.block.BlockStateWrapper;
|
||||
import net.momirealms.craftengine.core.block.DelayedInitBlockState;
|
||||
import net.momirealms.craftengine.core.block.LazyBlockState;
|
||||
|
||||
public class BlockStateData implements ParticleData {
|
||||
private final DelayedInitBlockState blockState;
|
||||
private final LazyBlockState blockState;
|
||||
|
||||
public BlockStateData(DelayedInitBlockState blockState) {
|
||||
public BlockStateData(LazyBlockState blockState) {
|
||||
this.blockState = blockState;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user