Compare commits

..

2 Commits

Author SHA1 Message Date
Wynd 406fe6f861 Fixed slimes not splitting when hp is under 0 2024-08-19 01:03:12 +03:00
Wynd b73a52ed98 Furnace minecarts loading chunks around them 2024-08-19 00:52:30 +03:00
6 changed files with 90 additions and 8 deletions

View File

@ -46,6 +46,8 @@ public class ModConfig {
"Extra speed modifier when minecarts go over powered rails\nVanilla default is 1.0"); "Extra speed modifier when minecarts go over powered rails\nVanilla default is 1.0");
public static final Option<Boolean> FURNACE_MINECART_PUSH = make("Enable furnace minecarts push", true, public static final Option<Boolean> FURNACE_MINECART_PUSH = make("Enable furnace minecarts push", true,
"Enables furance minecarts to push forward the first minecart it comes in contact with"); "Enables furance minecarts to push forward the first minecart it comes in contact with");
public static final Option<Boolean> FURNACE_MINECART_CHUNK_LOADING = make("Enable furnace minecarts to load chunks", true,
"Name says it all, furnace minecarts will load chunks as they go on tracks.");
public static final Option<Boolean> FIX_BOW_MODEL = make("Fix bow model", true, public static final Option<Boolean> FIX_BOW_MODEL = make("Fix bow model", true,
"Makes the box model held by players and skeletons bigger and facing forward"); "Makes the box model held by players and skeletons bigger and facing forward");
@ -73,6 +75,8 @@ public class ModConfig {
"Fixes double doors not being in their correct state when pressure plates are used to open them"); "Fixes double doors not being in their correct state when pressure plates are used to open them");
public static final Option<Boolean> FIX_SLABS_RECIPE = make("Fix Slabs Recipe", true, public static final Option<Boolean> FIX_SLABS_RECIPE = make("Fix Slabs Recipe", true,
"Givs two slabs for every block, since 1 block = 2 slabs => 3 blocks = 6 slabs (instead of 3)"); "Givs two slabs for every block, since 1 block = 2 slabs => 3 blocks = 6 slabs (instead of 3)");
public static final Option<Boolean> FIX_SLIME_SPLITS = make("Fix Slime Splits", true,
"Fixes slimes not splitting if their HP is not exactly zero");
private static ModConfig instance = new ModConfig(); private static ModConfig instance = new ModConfig();
public static final ModConfig instance() { public static final ModConfig instance() {

View File

@ -92,15 +92,34 @@ public class WyHelper {
} }
public static void cheatCommand(Player player) { public static void cheatCommand(Player player) {
// Slime slime = new Slime(player.level);
// slime.setPositionAndAngles(player.x, player.y + 0.5D, player.z, player.level.rand.nextFloat() * 360.0F, 0.0F);
// player.level.spawnEntity(slime);
// slime.setSize(10);
// player.level.entities.stream().filter(e -> !(e instanceof Player)).forEach((e) -> ((net.minecraft.entity.Entity)e).remove());
// player.dropItem(new ItemInstance(Tile.LADDER, 64)); // player.dropItem(new ItemInstance(Tile.LADDER, 64));
// player.dropItem(new ItemInstance(ItemType.minecartChest, 1)); // player.dropItem(new ItemInstance(ItemType.minecart, 1));
// player.dropItem(new ItemInstance(ItemType.minecartFurnace, 1));
// player.dropItem(new ItemInstance(ItemType.coal, 64)); // player.dropItem(new ItemInstance(ItemType.coal, 64));
// player.dropItem(new ItemInstance(Tile.GOLDEN_RAIL, 64)); // player.dropItem(new ItemInstance(Tile.GOLDEN_RAIL, 64));
// player.dropItem(new ItemInstance(Tile.COBBLESTONE, 64));
player.level.setLevelTime(0); // player.level.setTile((int)player.x, (int)player.y, (int)player.z, Tile.COBBLESTONE.id);
player.level.getProperties().setRaining(false);
player.level.getProperties().setRainTime(0); // int x = 248;
player.level.getProperties().setThundering(false); // int y = 79;
player.level.getProperties().setThunderTime(0); // int z = -65;
//
// for (int i = 0; i < 500; i++) {
// player.level.setTile(x + i, y, z, Tile.REDSTONE_TORCH_LIT.id);
// }
// player.level.setLevelTime(0);
// player.level.getProperties().setRaining(false);
// player.level.getProperties().setRainTime(0);
// player.level.getProperties().setThundering(false);
// player.level.getProperties().setThunderTime(0);
} }
} }

View File

@ -5,7 +5,11 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.entity.Entity;
import net.minecraft.entity.Minecart;
import net.minecraft.level.Level; import net.minecraft.level.Level;
import net.minecraft.util.maths.MathsHelper;
import xyz.pixelatedw.finalbeta.ModConfig;
import xyz.pixelatedw.finalbeta.WyHelper; import xyz.pixelatedw.finalbeta.WyHelper;
@Mixin(Level.class) @Mixin(Level.class)
@ -16,4 +20,38 @@ public class LevelMixin {
WyHelper.playTime++; WyHelper.playTime++;
} }
@Inject(method="updatePosition", at = @At("TAIL"))
public void updatePosition(Entity entity, boolean forceUpdate, CallbackInfo ci) {
if (ModConfig.FURNACE_MINECART_CHUNK_LOADING.get() && entity instanceof Minecart) {
Minecart minecart = ((Minecart) entity);
int x = MathsHelper.floor(entity.x);
int z = MathsHelper.floor(entity.z);
/*
* TODO This is very likely not optimal, we could probably do better
* and only load "forward" chunks relative to the cart's direction,
* but its barely noticeable in my tests and at least at the moment
* I don't care enough for this optimization.
*/
int area = 64;
boolean isRegionLoaded = entity.level.isRegionLoaded(x - area, 0, z - area, x + area, 128, z + area);
if (!isRegionLoaded && minecart.type == 2) {
loadRegion(entity.level, x - area, z - area, x + area, z + area);
}
}
}
private void loadRegion(Level level, int minX, int minZ, int maxX, int maxZ) {
minX >>= 4;
minZ >>= 4;
maxX >>= 4;
maxZ >>= 4;
for (int x = minX; x <= maxX; ++x) {
for (int z = minZ; z <= maxZ; ++z) {
if (!level.getLevelSource().isChunkLoaded(x, z)) {
level.getLevelSource().loadChunk(x, z);
}
}
}
}
} }

View File

@ -66,7 +66,7 @@ public class MinecartMixin {
private double getSpeedLimit(final double speedLimit) { private double getSpeedLimit(final double speedLimit) {
return ModConfig.MINECART_MAX_SPEED.get(); return ModConfig.MINECART_MAX_SPEED.get();
} }
@Inject(method = "tick", at = @At("TAIL")) @Inject(method = "tick", at = @At("TAIL"))
public void tick(CallbackInfo ci) { public void tick(CallbackInfo ci) {
Minecart minecart = (Minecart) (Object) this; Minecart minecart = (Minecart) (Object) this;

View File

@ -0,0 +1,20 @@
package xyz.pixelatedw.finalbeta.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.entity.monster.Slime;
import xyz.pixelatedw.finalbeta.ModConfig;
@Mixin(Slime.class)
public class SlimeMixin {
@Inject(method = "remove", at = @At("HEAD"))
public void remove(CallbackInfo ci) {
if (ModConfig.FIX_SLIME_SPLITS.get()) {
Slime slime = ((Slime) (Object) this);
slime.health = Math.max(slime.health, 0);
}
}
}

View File

@ -41,7 +41,8 @@
"CraftingInventoryMixin", "CraftingInventoryMixin",
"RecipeRegistryMixin", "RecipeRegistryMixin",
"SnowballMixin", "SnowballMixin",
"EntityMixin" "EntityMixin",
"SlimeMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": -1 "defaultRequire": -1