mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-27 19:09:09 +00:00
Added fix command
This commit is contained in:
@@ -53,6 +53,11 @@ public abstract class AbstractCustomCropsBlock implements CustomCropsBlock {
|
||||
return CustomCropsBlockState.create(this, compoundMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomCropsBlockState createBlockState(String itemID) {
|
||||
return createBlockState();
|
||||
}
|
||||
|
||||
public String id(CustomCropsBlockState state) {
|
||||
return state.get("key").getAsStringTag()
|
||||
.map(StringTag::getValue)
|
||||
|
||||
@@ -275,6 +275,19 @@ public class CropBlock extends AbstractCustomCropsBlock {
|
||||
ActionManager.trigger(context, stageConfig.interactActions());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomCropsBlockState createBlockState(String itemID) {
|
||||
List<CropConfig> configList = Registries.STAGE_TO_CROP_UNSAFE.get(itemID);
|
||||
if (configList == null || configList.size() != 1) return null;
|
||||
CropConfig cropConfig = configList.get(0);
|
||||
CustomCropsBlockState state = createBlockState();
|
||||
CropStageConfig stageConfig = cropConfig.stageByID(itemID);
|
||||
assert stageConfig != null;
|
||||
point(state, stageConfig.point());
|
||||
id(state, cropConfig.id());
|
||||
return state;
|
||||
}
|
||||
|
||||
public CustomCropsBlockState fixOrGetState(CustomCropsWorld<?> world, Pos3 pos3, String stageID) {
|
||||
List<CropConfig> configList = Registries.STAGE_TO_CROP_UNSAFE.get(stageID);
|
||||
if (configList == null) return null;
|
||||
@@ -296,7 +309,7 @@ public class CropBlock extends AbstractCustomCropsBlock {
|
||||
CropStageConfig stageConfig = cropConfig.stageByID(stageID);
|
||||
assert stageConfig != null;
|
||||
int point = stageConfig.point();
|
||||
CustomCropsBlockState state = BuiltInBlockMechanics.CROP.createBlockState();
|
||||
CustomCropsBlockState state = createBlockState();
|
||||
point(state, point);
|
||||
id(state, cropConfig.id());
|
||||
world.addBlockState(pos3, state).ifPresent(previous -> {
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.momirealms.customcrops.api.core.wrapper.WrappedPlaceEvent;
|
||||
import net.momirealms.customcrops.api.misc.NamedTextColor;
|
||||
import net.momirealms.customcrops.common.util.Key;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface CustomCropsBlock {
|
||||
|
||||
@@ -44,6 +45,14 @@ public interface CustomCropsBlock {
|
||||
*/
|
||||
CustomCropsBlockState createBlockState();
|
||||
|
||||
/**
|
||||
* Create a CustomCropsBlockState based on the item id
|
||||
*
|
||||
* @return CustomCropsBlockState
|
||||
*/
|
||||
@Nullable
|
||||
CustomCropsBlockState createBlockState(String itemID);
|
||||
|
||||
/**
|
||||
* Create a CustomCropsBlockState based on this type and provided data
|
||||
*
|
||||
|
||||
@@ -26,7 +26,10 @@ import net.momirealms.customcrops.api.core.mechanic.pot.PotConfig;
|
||||
import net.momirealms.customcrops.api.core.world.CustomCropsBlockState;
|
||||
import net.momirealms.customcrops.api.core.world.CustomCropsWorld;
|
||||
import net.momirealms.customcrops.api.core.world.Pos3;
|
||||
import net.momirealms.customcrops.api.core.wrapper.WrappedBreakEvent;
|
||||
import net.momirealms.customcrops.api.core.wrapper.WrappedInteractEvent;
|
||||
import net.momirealms.customcrops.api.event.ScarecrowBreakEvent;
|
||||
import net.momirealms.customcrops.api.util.EventUtils;
|
||||
import net.momirealms.customcrops.api.util.LocationUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -47,6 +50,18 @@ public class DeadCrop extends AbstractCustomCropsBlock {
|
||||
// do not restore
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomCropsBlockState createBlockState(String itemID) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBreak(WrappedBreakEvent event) {
|
||||
CustomCropsWorld<?> world = event.world();
|
||||
Pos3 pos3 = Pos3.from(event.location());
|
||||
world.removeBlockState(pos3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInteract(WrappedInteractEvent event) {
|
||||
final Player player = event.player();
|
||||
|
||||
@@ -322,6 +322,18 @@ public class PotBlock extends AbstractCustomCropsBlock {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomCropsBlockState createBlockState(String itemID) {
|
||||
PotConfig potConfig = Registries.ITEM_TO_POT.get(itemID);
|
||||
if (potConfig == null) {
|
||||
return null;
|
||||
}
|
||||
CustomCropsBlockState state = createBlockState();
|
||||
id(state, potConfig.id());
|
||||
water(state, potConfig.isWet(itemID) ? 1 : 0);
|
||||
return state;
|
||||
}
|
||||
|
||||
public CustomCropsBlockState fixOrGetState(CustomCropsWorld<?> world, Pos3 pos3, PotConfig potConfig, String blockID) {
|
||||
if (potConfig == null) return null;
|
||||
Optional<CustomCropsBlockState> optionalPotState = world.getBlockState(pos3);
|
||||
@@ -333,7 +345,7 @@ public class PotBlock extends AbstractCustomCropsBlock {
|
||||
}
|
||||
}
|
||||
}
|
||||
CustomCropsBlockState state = BuiltInBlockMechanics.POT.createBlockState();
|
||||
CustomCropsBlockState state = createBlockState();
|
||||
id(state, potConfig.id());
|
||||
water(state, potConfig.isWet(blockID) ? 1 : 0);
|
||||
world.addBlockState(pos3, state).ifPresent(previous -> {
|
||||
|
||||
@@ -232,6 +232,18 @@ public class SprinklerBlock extends AbstractCustomCropsBlock {
|
||||
ActionManager.trigger(context, config.interactActions());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomCropsBlockState createBlockState(String itemID) {
|
||||
SprinklerConfig config = Registries.ITEM_TO_SPRINKLER.get(itemID);
|
||||
if (config == null) {
|
||||
return null;
|
||||
}
|
||||
CustomCropsBlockState state = createBlockState();
|
||||
id(state, config.id());
|
||||
water(state, itemID.equals(config.threeDItemWithWater()) ? 1 : 0);
|
||||
return state;
|
||||
}
|
||||
|
||||
public CustomCropsBlockState fixOrGetState(CustomCropsWorld<?> world, Pos3 pos3, SprinklerConfig sprinklerConfig, String blockID) {
|
||||
Optional<CustomCropsBlockState> optionalPotState = world.getBlockState(pos3);
|
||||
if (optionalPotState.isPresent()) {
|
||||
@@ -242,7 +254,7 @@ public class SprinklerBlock extends AbstractCustomCropsBlock {
|
||||
}
|
||||
}
|
||||
}
|
||||
CustomCropsBlockState state = BuiltInBlockMechanics.SPRINKLER.createBlockState();
|
||||
CustomCropsBlockState state = createBlockState();
|
||||
id(state, sprinklerConfig.id());
|
||||
water(state, blockID.equals(sprinklerConfig.threeDItemWithWater()) ? 1 : 0);
|
||||
world.addBlockState(pos3, state).ifPresent(previous -> {
|
||||
|
||||
@@ -182,8 +182,6 @@ public class CustomCropsWorldImpl<W> implements CustomCropsWorld<W> {
|
||||
public Optional<CustomCropsBlockState> addBlockState(Pos3 location, CustomCropsBlockState block) {
|
||||
ChunkPos pos = location.toChunkPos();
|
||||
CustomCropsChunk chunk = getOrCreateChunk(pos);
|
||||
// to let the bukkit system trigger the ChunkUnloadEvent later
|
||||
chunk.load(true);
|
||||
return chunk.addBlockState(location, block);
|
||||
}
|
||||
|
||||
@@ -437,7 +435,10 @@ public class CustomCropsWorldImpl<W> implements CustomCropsWorld<W> {
|
||||
if (chunk != null) {
|
||||
return chunk;
|
||||
}
|
||||
return this.adaptor.loadChunk(this, chunkPos, true);
|
||||
chunk = this.adaptor.loadChunk(this, chunkPos, true);
|
||||
// to let the bukkit system trigger the ChunkUnloadEvent later
|
||||
chunk.load(true);
|
||||
return chunk;
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user