9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-29 11:59:15 +00:00

force tick

This commit is contained in:
XiaoMoMi
2024-09-02 00:31:29 +08:00
parent ab6d8527ec
commit 3f98c117fc
24 changed files with 278 additions and 49 deletions

View File

@@ -38,6 +38,7 @@ public class MappedRegistry<K, T> implements WriteableRegistry<K, T> {
public void register(K key, T value) {
byKey.put(key, value);
byValue.put(value, key);
byID.add(value);
}
@Override
@@ -67,6 +68,16 @@ public class MappedRegistry<K, T> implements WriteableRegistry<K, T> {
return byKey.get(key);
}
@Override
public boolean containsKey(@Nullable K key) {
return byKey.containsKey(key);
}
@Override
public boolean containsValue(@Nullable T value) {
return byValue.containsKey(value);
}
@NotNull
@Override
public Iterator<T> iterator() {

View File

@@ -30,4 +30,8 @@ public interface Registry<K, T> extends IdMap<T> {
@Nullable
T get(@Nullable K key);
boolean containsKey(@Nullable K key);
boolean containsValue(@Nullable T value);
}

View File

@@ -153,6 +153,11 @@ public class CropBlock extends AbstractCustomCropsBlock {
fixOrGetState(world, pos3, event.placedID());
}
@Override
public boolean isBlockInstance(String id) {
return Registries.STAGE_TO_CROP_UNSAFE.containsKey(id);
}
@Override
public void onInteract(WrappedInteractEvent event) {
final Player player = event.player();
@@ -287,8 +292,8 @@ public class CropBlock extends AbstractCustomCropsBlock {
id(state, cropConfig.id());
world.addBlockState(pos3, state).ifPresent(previous -> {
BukkitCustomCropsPlugin.getInstance().debug(
"Overwrite old data with " + state.compoundMap().toString() +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous.compoundMap().toString()
"Overwrite old data with " + state +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous
);
});
return state;

View File

@@ -52,7 +52,7 @@ public class CrowAttack {
}
}
this.viewers = viewers.toArray(new Player[0]);
this.cropLocation = location.clone().add(RandomUtils.generateRandomDouble(-0.25, 0.25), 0, RandomUtils.generateRandomDouble(-0.25, 0.25));
this.cropLocation = LocationUtils.toBlockCenterLocation(location).add(RandomUtils.generateRandomDouble(-0.25, 0.25), 0, RandomUtils.generateRandomDouble(-0.25, 0.25));
float yaw = RandomUtils.generateRandomInt(-180, 180);
this.cropLocation.setYaw(yaw);
this.flyModel = flyModel;
@@ -66,47 +66,39 @@ public class CrowAttack {
public void start() {
if (this.viewers.length == 0) return;
FakeArmorStand fake1 = SparrowHeart.getInstance().createFakeArmorStand(dynamicLocation);
fake1.invisible(true);
fake1.small(true);
fake1.equipment(EquipmentSlot.HEAD, flyModel);
FakeArmorStand fake2 = SparrowHeart.getInstance().createFakeArmorStand(cropLocation);
fake1.invisible(true);
fake1.small(true);
fake1.equipment(EquipmentSlot.HEAD, standModel);
FakeArmorStand fake = SparrowHeart.getInstance().createFakeArmorStand(dynamicLocation);
fake.invisible(true);
fake.small(true);
fake.equipment(EquipmentSlot.HEAD, flyModel);
for (Player player : this.viewers) {
fake1.spawn(player);
fake.spawn(player);
}
this.task = BukkitCustomCropsPlugin.getInstance().getScheduler().asyncRepeating(() -> {
timer++;
if (timer < 100) {
dynamicLocation.add(vectorDown);
for (Player player : this.viewers) {
SparrowHeart.getInstance().sendClientSideTeleportEntity(player, dynamicLocation, false, fake1.entityID());
SparrowHeart.getInstance().sendClientSideTeleportEntity(player, dynamicLocation, false, fake.entityID());
}
} else if (timer == 100){
} else if (timer == 100) {
fake.equipment(EquipmentSlot.HEAD, standModel);
for (Player player : this.viewers) {
fake1.destroy(player);
}
for (Player player : this.viewers) {
fake2.spawn(player);
fake.updateEquipment(player);
}
} else if (timer == 150) {
fake.equipment(EquipmentSlot.HEAD, flyModel);
for (Player player : this.viewers) {
fake2.destroy(player);
}
for (Player player : this.viewers) {
fake1.spawn(player);
fake.updateEquipment(player);
}
} else if (timer > 150) {
dynamicLocation.add(vectorUp);
for (Player player : this.viewers) {
SparrowHeart.getInstance().sendClientSideTeleportEntity(player, dynamicLocation, false, fake1.entityID());
SparrowHeart.getInstance().sendClientSideTeleportEntity(player, dynamicLocation, false, fake.entityID());
}
}
if (timer > 300) {
if (timer > 250) {
for (Player player : this.viewers) {
fake1.destroy(player);
fake.destroy(player);
}
task.cancel();
}

View File

@@ -43,4 +43,6 @@ public interface CustomCropsBlock {
void onBreak(WrappedBreakEvent event);
void onPlace(WrappedPlaceEvent event);
boolean isBlockInstance(String id);
}

View File

@@ -90,12 +90,17 @@ public class GreenhouseBlock extends AbstractCustomCropsBlock {
CustomCropsWorld<?> world = event.world();
world.addBlockState(pos3, state).ifPresent(previous -> {
BukkitCustomCropsPlugin.getInstance().debug(
"Overwrite old data with " + state.compoundMap().toString() +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous.compoundMap().toString()
"Overwrite old data with " + state +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous
);
});
}
@Override
public boolean isBlockInstance(String id) {
return ConfigManager.greenhouse().contains(id);
}
public CustomCropsBlockState getOrFixState(CustomCropsWorld<?> world, Pos3 pos3) {
Optional<CustomCropsBlockState> optional = world.getBlockState(pos3);
if (optional.isPresent() && optional.get().type() instanceof GreenhouseBlock) {
@@ -104,8 +109,8 @@ public class GreenhouseBlock extends AbstractCustomCropsBlock {
CustomCropsBlockState state = createBlockState();
world.addBlockState(pos3, state).ifPresent(previous -> {
BukkitCustomCropsPlugin.getInstance().debug(
"Overwrite old data with " + state.compoundMap().toString() +
" at pos3[" + world.worldName() + "," + pos3 + "] which used to be " + previous.compoundMap().toString()
"Overwrite old data with " + state +
" at pos3[" + world.worldName() + "," + pos3 + "] which used to be " + previous
);
});
return state;

View File

@@ -199,13 +199,18 @@ public class PotBlock extends AbstractCustomCropsBlock {
world.addBlockState(pos3, state).ifPresent(previous -> {
BukkitCustomCropsPlugin.getInstance().debug(
"Overwrite old data with " + state.compoundMap().toString() +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous.compoundMap().toString()
"Overwrite old data with " + state +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous
);
});
ActionManager.trigger(context, config.placeActions());
}
@Override
public boolean isBlockInstance(String id) {
return Registries.ITEM_TO_POT.containsKey(id);
}
@Override
public void onInteract(WrappedInteractEvent event) {
PotConfig potConfig = Registries.ITEM_TO_POT.get(event.relatedID());
@@ -291,8 +296,8 @@ public class PotBlock extends AbstractCustomCropsBlock {
water(state, potConfig.isWet(blockID) ? 1 : 0);
world.addBlockState(pos3, state).ifPresent(previous -> {
BukkitCustomCropsPlugin.getInstance().debug(
"Overwrite old data with " + state.compoundMap().toString() +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous.compoundMap().toString()
"Overwrite old data with " + state +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous
);
});
return state;

View File

@@ -90,12 +90,17 @@ public class ScarecrowBlock extends AbstractCustomCropsBlock {
CustomCropsWorld<?> world = event.world();
world.addBlockState(pos3, state).ifPresent(previous -> {
BukkitCustomCropsPlugin.getInstance().debug(
"Overwrite old data with " + state.compoundMap().toString() +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous.compoundMap().toString()
"Overwrite old data with " + state +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous
);
});
}
@Override
public boolean isBlockInstance(String id) {
return ConfigManager.scarecrow().contains(id);
}
public CustomCropsBlockState getOrFixState(CustomCropsWorld<?> world, Pos3 pos3) {
Optional<CustomCropsBlockState> optional = world.getBlockState(pos3);
if (optional.isPresent() && optional.get().type() instanceof ScarecrowBlock) {
@@ -104,8 +109,8 @@ public class ScarecrowBlock extends AbstractCustomCropsBlock {
CustomCropsBlockState state = createBlockState();
world.addBlockState(pos3, state).ifPresent(previous -> {
BukkitCustomCropsPlugin.getInstance().debug(
"Overwrite old data with " + state.compoundMap().toString() +
" at pos3[" + world.worldName() + "," + pos3 + "] which used to be " + previous.compoundMap().toString()
"Overwrite old data with " + state +
" at pos3[" + world.worldName() + "," + pos3 + "] which used to be " + previous
);
});
return state;

View File

@@ -137,6 +137,11 @@ public class SprinklerBlock extends AbstractCustomCropsBlock {
ActionManager.trigger(context, config.placeActions());
}
@Override
public boolean isBlockInstance(String id) {
return Registries.ITEM_TO_SPRINKLER.containsKey(id);
}
@Override
public void onInteract(WrappedInteractEvent event) {
SprinklerConfig config = Registries.ITEM_TO_SPRINKLER.get(event.relatedID());
@@ -225,8 +230,8 @@ public class SprinklerBlock extends AbstractCustomCropsBlock {
water(state, blockID.equals(sprinklerConfig.threeDItemWithWater()) ? 1 : 0);
world.addBlockState(pos3, state).ifPresent(previous -> {
BukkitCustomCropsPlugin.getInstance().debug(
"Overwrite old data with " + state.compoundMap().toString() +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous.compoundMap().toString()
"Overwrite old data with " + state +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous
);
});
return state;

View File

@@ -118,8 +118,8 @@ public class SeedItem extends AbstractCustomCropsItem {
cropBlock.point(state, point);
world.addBlockState(pos3, state).ifPresent(previous -> {
BukkitCustomCropsPlugin.getInstance().debug(
"Overwrite old data with " + state.compoundMap().toString() +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous.compoundMap().toString()
"Overwrite old data with " + state +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous
);
});

View File

@@ -111,8 +111,8 @@ public class SprinklerItem extends AbstractCustomCropsItem {
BukkitCustomCropsPlugin.getInstance().getItemManager().place(LocationUtils.toSurfaceCenterLocation(targetLocation), config.existenceForm(), config.threeDItem(), FurnitureRotation.NONE);
world.addBlockState(pos3, state).ifPresent(previous -> {
BukkitCustomCropsPlugin.getInstance().debug(
"Overwrite old data with " + state.compoundMap().toString() +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous.compoundMap().toString()
"Overwrite old data with " + state +
" at location[" + world.worldName() + "," + pos3 + "] which used to be " + previous
);
});
ActionManager.trigger(context, config.placeActions());

View File

@@ -179,7 +179,7 @@ public interface CustomCropsChunk {
CustomCropsSection getSection(int sectionID);
Collection<CustomCropsSection> sections();
CustomCropsSection[] sections();
Optional<CustomCropsSection> removeSection(int sectionID);

View File

@@ -257,8 +257,8 @@ public class CustomCropsChunkImpl implements CustomCropsChunk {
}
@Override
public Collection<CustomCropsSection> sections() {
return loadedSections.values();
public CustomCropsSection[] sections() {
return loadedSections.values().toArray(new CustomCropsSection[0]);
}
@Override

View File

@@ -80,6 +80,8 @@ public interface CustomCropsWorld<W> {
int getChunkBlockAmount(Pos3 pos3, Class<? extends CustomCropsBlock> clazz);
CustomCropsChunk[] loadedChunks();
/**
* Get the state of the block at a certain location
*

View File

@@ -131,6 +131,11 @@ public class CustomCropsWorldImpl<W> implements CustomCropsWorld<W> {
}
}
@Override
public CustomCropsChunk[] loadedChunks() {
return loadedChunks.values().toArray(new CustomCropsChunk[0]);
}
@NotNull
@Override
public Optional<CustomCropsBlockState> getBlockState(Pos3 location) {