Furnace minecarts loading chunks around them
parent
94ceb63a1f
commit
b73a52ed98
|
@ -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");
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.util.HashMap;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.player.Player;
|
import net.minecraft.entity.player.Player;
|
||||||
|
import net.minecraft.item.ItemInstance;
|
||||||
|
import net.minecraft.item.ItemType;
|
||||||
|
|
||||||
public class WyHelper {
|
public class WyHelper {
|
||||||
|
|
||||||
|
@ -92,10 +94,25 @@ public class WyHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cheatCommand(Player player) {
|
public static void cheatCommand(Player player) {
|
||||||
|
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.coal, 64));
|
player.dropItem(new ItemInstance(ItemType.minecartFurnace, 1));
|
||||||
|
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.setTile((int)player.x, (int)player.y, (int)player.z, Tile.COBBLESTONE.id);
|
||||||
|
|
||||||
|
// int x = 248;
|
||||||
|
// int y = 79;
|
||||||
|
// 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.setLevelTime(0);
|
||||||
player.level.getProperties().setRaining(false);
|
player.level.getProperties().setRaining(false);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue