mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-11-14 15:40:49 +01:00
Fixed ageable cast class exception Fixes #5224
Fixed Herbalism not replanting certain crops
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
Version 2.2.045
|
||||||
|
Fixed an error that could happen when replanting crops with Green Thumb
|
||||||
|
Green Thumb now replants harvested plants faster
|
||||||
|
|
||||||
|
NOTES:
|
||||||
|
The delay from a plant being replanted from Green Thumb is intentional, and while looking into bugs it seemd maybe a tad slow, so I sped it up a bit.
|
||||||
|
|
||||||
Version 2.2.044
|
Version 2.2.044
|
||||||
Fixed copper armor and tools not working with Repair or Salvage
|
Fixed copper armor and tools not working with Repair or Salvage
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ public class DelayedCropReplant extends CancellableRunnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Block cropBlock = cropLocation.getBlock();
|
final BlockState blockState = cropLocation.getBlock().getState();
|
||||||
BlockState currentState = cropBlock.getState();
|
|
||||||
PlantAnchorType plantAnchorType = PlantAnchorType.NORMAL;
|
PlantAnchorType plantAnchorType = PlantAnchorType.NORMAL;
|
||||||
|
|
||||||
//Remove the metadata marking the block as recently replanted
|
//Remove the metadata marking the block as recently replanted
|
||||||
@@ -64,50 +63,43 @@ public class DelayedCropReplant extends CancellableRunnable {
|
|||||||
wasImmaturePlant = true;
|
wasImmaturePlant = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Two kinds of air in Minecraft
|
if (blockIsAirOrExpectedCrop(blockState)) {
|
||||||
if (currentState.getType().equals(cropMaterial) || currentState.getType()
|
// Modify the new state of the block, not any old snapshot of it
|
||||||
.equals(Material.AIR) || currentState.getType().equals(Material.CAVE_AIR)) {
|
blockState.setType(cropMaterial);
|
||||||
// if (currentState.getBlock().getRelative(BlockFace.DOWN))
|
final BlockData newData = blockState.getBlockData();
|
||||||
//The space is not currently occupied by a block so we can fill it
|
|
||||||
cropBlock.setType(cropMaterial);
|
|
||||||
|
|
||||||
//Get new state (necessary?)
|
// Immature plants should be age 0, others get the desired age
|
||||||
BlockState newState = cropBlock.getState();
|
int age = wasImmaturePlant ? 0 : desiredCropAge;
|
||||||
BlockData newData = newState.getBlockData();
|
|
||||||
|
|
||||||
int age = 0;
|
|
||||||
|
|
||||||
//Crop age should always be 0 if the plant was immature
|
|
||||||
if (!wasImmaturePlant) {
|
|
||||||
age = desiredCropAge;
|
|
||||||
//Otherwise make the plant the desired age
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newData instanceof Directional) {
|
if (newData instanceof Directional) {
|
||||||
//Cocoa Version
|
// Cocoa Version
|
||||||
Directional directional = (Directional) newState.getBlockData();
|
Directional directional = (Directional) blockState.getBlockData();
|
||||||
directional.setFacing(cropFace);
|
directional.setFacing(cropFace);
|
||||||
|
|
||||||
newState.setBlockData(directional);
|
blockState.setBlockData(directional);
|
||||||
|
|
||||||
if (newData instanceof Cocoa) {
|
if (newData instanceof Cocoa) {
|
||||||
plantAnchorType = PlantAnchorType.COCOA;
|
plantAnchorType = PlantAnchorType.COCOA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Age the crop
|
if (blockState.getBlockData() instanceof Ageable ageable) {
|
||||||
Ageable ageable = (Ageable) newState.getBlockData();
|
|
||||||
ageable.setAge(age);
|
ageable.setAge(age);
|
||||||
newState.setBlockData(ageable);
|
blockState.setBlockData(ageable);
|
||||||
|
blockState.update(true, true);
|
||||||
newState.update(true, true);
|
|
||||||
|
|
||||||
//Play an effect
|
//Play an effect
|
||||||
ParticleEffectUtils.playGreenThumbEffect(cropLocation);
|
ParticleEffectUtils.playGreenThumbEffect(cropLocation);
|
||||||
mcMMO.p.getFoliaLib().getScheduler().runAtLocationLater(newState.getLocation(),
|
mcMMO.p.getFoliaLib().getScheduler().runAtLocationLater(blockState.getLocation(),
|
||||||
new PhysicsBlockUpdate(newState.getBlock(), cropFace, plantAnchorType), 1);
|
new PhysicsBlockUpdate(blockState.getBlock(), cropFace, plantAnchorType), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean blockIsAirOrExpectedCrop(BlockState blockState) {
|
||||||
|
return blockState.getType().equals(cropMaterial) || blockState.getType()
|
||||||
|
.equals(Material.AIR) || blockState.getType().equals(Material.CAVE_AIR);
|
||||||
|
}
|
||||||
|
|
||||||
private enum PlantAnchorType {
|
private enum PlantAnchorType {
|
||||||
NORMAL,
|
NORMAL,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.gmail.nossr50.skills.herbalism;
|
|||||||
|
|
||||||
import static com.gmail.nossr50.util.ItemUtils.hasItemIncludingOffHand;
|
import static com.gmail.nossr50.util.ItemUtils.hasItemIncludingOffHand;
|
||||||
import static com.gmail.nossr50.util.ItemUtils.removeItemIncludingOffHand;
|
import static com.gmail.nossr50.util.ItemUtils.removeItemIncludingOffHand;
|
||||||
|
import static com.gmail.nossr50.util.Misc.TICK_CONVERSION_FACTOR;
|
||||||
import static com.gmail.nossr50.util.Misc.getBlockCenter;
|
import static com.gmail.nossr50.util.Misc.getBlockCenter;
|
||||||
import static com.gmail.nossr50.util.text.ConfigStringUtils.getMaterialConfigString;
|
import static com.gmail.nossr50.util.text.ConfigStringUtils.getMaterialConfigString;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
@@ -822,7 +823,7 @@ public class HerbalismManager extends SkillManager {
|
|||||||
mcMMO.p.getFoliaLib().getScheduler()
|
mcMMO.p.getFoliaLib().getScheduler()
|
||||||
.runAtLocationLater(blockBreakEvent.getBlock().getLocation(),
|
.runAtLocationLater(blockBreakEvent.getBlock().getLocation(),
|
||||||
new DelayedCropReplant(blockBreakEvent, cropState, desiredCropAge,
|
new DelayedCropReplant(blockBreakEvent, cropState, desiredCropAge,
|
||||||
isImmature), 2 * Misc.TICK_CONVERSION_FACTOR);
|
isImmature), TICK_CONVERSION_FACTOR);
|
||||||
blockBreakEvent.getBlock().setMetadata(MetadataConstants.METADATA_KEY_REPLANT,
|
blockBreakEvent.getBlock().setMetadata(MetadataConstants.METADATA_KEY_REPLANT,
|
||||||
new RecentlyReplantedCropMeta(mcMMO.p, true));
|
new RecentlyReplantedCropMeta(mcMMO.p, true));
|
||||||
}
|
}
|
||||||
@@ -914,9 +915,7 @@ public class HerbalismManager extends SkillManager {
|
|||||||
|
|
||||||
//Immature plants will start over at 0
|
//Immature plants will start over at 0
|
||||||
if (!isAgeableMature(ageable)) {
|
if (!isAgeableMature(ageable)) {
|
||||||
// blockBreakEvent.setCancelled(true);
|
|
||||||
startReplantTask(0, blockBreakEvent, blockState, true);
|
startReplantTask(0, blockBreakEvent, blockState, true);
|
||||||
// blockState.setType(Material.AIR);
|
|
||||||
blockBreakEvent.setDropItems(false);
|
blockBreakEvent.setDropItems(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user