Fences with slim hitboxes, bookshelves dropping 3 books and made mixins not crash on fail

master
Wynd 2024-01-06 20:46:45 +02:00
parent cbb7e90e79
commit 09cd62e112
8 changed files with 214 additions and 35 deletions

View File

@ -20,6 +20,8 @@ public class ModConfig {
public static final Option<Boolean> ENABLE_CLOUDS = make("Enable Clouds", true, "Enables the rendering of clouds");
public static final Option<Boolean> DISABLE_ID_TAGS = make("Disable ID Tags", true,
"Disables id tags showing above entities in F3 mode");
public static final Option<Boolean> BOOKSHELVES_DROP = make("Bookshelves Drops", true,
"Drops 3 books when breaking a bookshelf");
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");

View File

@ -54,6 +54,11 @@ public class WyHelper {
public static void cheatCommand(Player player) {
// player.dropItem(new ItemInstance(Tile.FENCE, 64));
// player.dropItem(new ItemInstance(Tile.STONE_PRESSURE_PLATE, 64));
// player.dropItem(new ItemInstance(Tile.BOOKSHELF, 64));
// player.dropItem(new ItemInstance(Tile.SNOW));
// Random rand = new Random();
// player.level.playSound(player, "random.break", 1, (rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F);
@ -77,10 +82,10 @@ public class WyHelper {
// enemy.setPositionAndAngles(player.x + 2, player.y, player.z, 0.0f, 0.0f);
// player.level.spawnEntity(enemy);
// player.level.setLevelTime(0);
// player.level.getProperties().setRaining(false);
// player.level.getProperties().setRainTime(0);
// player.level.getProperties().setThundering(false);
// player.level.getProperties().setThunderTime(0);
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

@ -0,0 +1,38 @@
package xyz.pixelatedw.finalbeta.mixin;
import java.util.Random;
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.CallbackInfoReturnable;
import net.minecraft.item.ItemType;
import net.minecraft.tile.BookshelfTile;
import net.minecraft.tile.Tile;
import net.minecraft.tile.material.Material;
import xyz.pixelatedw.finalbeta.ModConfig;
@Mixin(BookshelfTile.class)
public class BookshelfTileMixin extends Tile {
public BookshelfTileMixin(int i, Material j) {
super(i, j);
}
@Inject(method = "getDropCount", at = @At("HEAD"), cancellable = true)
public void getDropCount(Random random, CallbackInfoReturnable<Integer> cir) {
if (ModConfig.BOOKSHELVES_DROP.get()) {
cir.setReturnValue(3);
}
}
@Override
public int getDropId(int i, Random random) {
if (ModConfig.BOOKSHELVES_DROP.get()) {
return ItemType.book.id;
}
return super.getDropId(i, random);
}
}

View File

@ -0,0 +1,60 @@
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.CallbackInfoReturnable;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.level.Level;
import net.minecraft.tile.FenceTile;
import net.minecraft.tile.Tile;
import net.minecraft.tile.material.Material;
import net.minecraft.util.maths.Box;
@Mixin(FenceTile.class)
public class FenceTileMixin extends Tile {
public FenceTileMixin(int i, Material j) {
super(i, j);
}
@Inject(method = "canPlaceAt", at = @At("HEAD"), cancellable = true)
public void canPlaceAt(Level arg, int i, int j, int k, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(true);
}
@Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true)
public void getCollisionShape(Level level, int x, int y, int z, CallbackInfoReturnable<Box> cir) {
cir.setReturnValue(createFenceBox(level, x, y, z, false));
}
@Override
@Environment(EnvType.CLIENT)
public Box getOutlineShape(Level level, int x, int y, int z) {
return createFenceBox(level, x, y, z, true);
}
private Box createFenceBox(Level level, int x, int y, int z, boolean isOutline) {
boolean eastCheck = level.getMaterial(x + 1, y, z).isSolid();
boolean westCheck = level.getMaterial(x - 1, y, z).isSolid();
boolean southCheck = level.getMaterial(x, y, z + 1).isSolid();
boolean northCheck = level.getMaterial(x, y, z - 1).isSolid();
Box box = Box.create(westCheck ? 0 : 0.375f, 0.0f, northCheck ? 0.0f : 0.375f, eastCheck ? 1.0f : 0.625f, 1.0F, southCheck ? 1.0f : 0.625f);
box.minX += x;
box.minY += y;
box.minZ += z;
box.maxX += x;
box.maxY += y;
box.maxZ += z;
if (!isOutline) {
box.maxY += 0.5f;
}
return box;
}
}

View File

@ -0,0 +1,26 @@
package xyz.pixelatedw.finalbeta.mixin;
import org.spongepowered.asm.mixin.Mixin;
import net.minecraft.tile.GrassTile;
import net.minecraft.tile.Tile;
import net.minecraft.tile.material.Material;
@Mixin(GrassTile.class)
public class GrassTileMixin extends Tile {
public GrassTileMixin(int i, Material j) {
super(i, j);
}
@Override
public int getTextureForSide(int i) {
if (i == 1) {
return 0;
} else if (i == 0) {
return 2;
} else {
return this.tex;
}
}
}

View File

@ -1,26 +0,0 @@
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.CallbackInfoReturnable;
import net.minecraft.tile.Tile;
@Mixin(Tile.class)
public class TileMixin {
@Inject(method = "getTextureForSide(I)I", at = @At("HEAD"), cancellable = true)
public void getTextureForSide(int i, CallbackInfoReturnable<Integer> ci) {
Tile tile = (Tile) (Object) this;
if (tile.id == Tile.GRASS.id) {
if (i == 1) {
ci.setReturnValue(0);
} else if (i == 0) {
ci.setReturnValue(2);
} else {
ci.setReturnValue(tile.tex);
}
}
}
}

View File

@ -6,18 +6,90 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.client.colour.GrassColour;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.TileRenderer;
import net.minecraft.level.TileView;
import net.minecraft.tile.Tile;
@Mixin(TileRenderer.class)
public class TileRendererMixin {
@Shadow
private TileView field_82;
@Shadow
private int field_83;
// Fence renderer to handle it connecting with other non-fence blocks
@Inject(method = "method_78", at = @At("HEAD"), cancellable = true)
public void fenceRenderer(Tile tile, int x, int y, int z, CallbackInfoReturnable<Boolean> cir) {
TileRenderer renderer = (TileRenderer) (Object) this;
int var5 = 0;
float var6 = 0.375F;
float var7 = 0.625F;
tile.setBoundingBox(var6, 0.0F, var6, var7, 1.0F, var7);
renderer.method_76(tile, x, y, z);
var5 = 1;
int var8 = 0;
int var9 = 0;
if (this.field_82.getMaterial(x - 1, y, z).isSolid() || this.field_82.getMaterial(x + 1, y, z).isSolid()) {
var8 = 1;
}
if (this.field_82.getMaterial(x, y, z - 1).isSolid() || this.field_82.getMaterial(x, y, z + 1).isSolid()) {
var9 = 1;
}
int var10 = this.field_82.getMaterial(x - 1, y, z).isSolid() ? 1 : 0;
int var11 = this.field_82.getMaterial(x + 1, y, z).isSolid() ? 1 : 0;
int var12 = this.field_82.getMaterial(x, y, z - 1).isSolid() ? 1 : 0;
int var13 = this.field_82.getMaterial(x, y, z + 1).isSolid() ? 1 : 0;
if (var8 == 0 && var9 == 0) {
var8 = 1;
}
var6 = 0.4375F;
var7 = 0.5625F;
float var14 = 0.75F;
float var15 = 0.9375F;
float var16 = var10 != 0 ? 0.0F : var6;
float var17 = var11 != 0 ? 1.0F : var7;
float var18 = var12 != 0 ? 0.0F : var6;
float var19 = var13 != 0 ? 1.0F : var7;
if (var8 != 0) {
tile.setBoundingBox(var16, var14, var6, var17, var15, var7);
renderer.method_76(tile, x, y, z);
var5 = 1;
}
if (var9 != 0) {
tile.setBoundingBox(var6, var14, var18, var7, var15, var19);
renderer.method_76(tile, x, y, z);
var5 = 1;
}
var14 = 0.375F;
var15 = 0.5625F;
if (var8 != 0) {
tile.setBoundingBox(var16, var14, var6, var17, var15, var7);
renderer.method_76(tile, x, y, z);
var5 = 1;
}
if (var9 != 0) {
tile.setBoundingBox(var6, var14, var18, var7, var15, var19);
renderer.method_76(tile, x, y, z);
var5 = 1;
}
tile.setBoundingBox(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
cir.setReturnValue(var5 == 1 ? true : false);
}
// Grass block texture using side textures for top fix
@Inject(method = "method_48", at = @At("HEAD"), cancellable = true)
public void grassBlockRenderer(Tile arg, int i, float f, CallbackInfo ci) {

View File

@ -27,10 +27,12 @@
"FurnaceEntityMixin",
"WorldRendererMixin",
"VideoSettingsScreenMixin",
"TileMixin",
"OverlayMixin"
"GrassTileMixin",
"OverlayMixin",
"BookshelfTileMixin",
"FenceTileMixin"
],
"injectors": {
"defaultRequire": 1
"defaultRequire": -1
}
}