Skip to content

Commit

Permalink
new: better lava cauldron
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Jul 14, 2023
1 parent 08813f4 commit 0de165c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/mendedminecarts/MendedMinecartsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MendedMinecartsMod implements ModInitializer {

public static final List<Setting> SETTINGS = new ArrayList<>();
public static final List<Setting> FLAT_SETTINGS = new ArrayList<>();
private static final String CONFIG_FILE = "./config/mendedminecarts.properties";
private static final String CONFIG_FILE = "./config/mendedminecarts.properties";

public static <T extends Setting> T addSetting(T setting) {
SETTINGS.add(setting);
Expand Down Expand Up @@ -94,6 +94,7 @@ public static <T extends Setting> T addSetting(T setting) {
public static final BooleanSetting ROTATE_CART_TO_RAIL = addSetting(new BooleanSetting("RotateCartToRail", false, Text.translatable("mendedminecarts.rotate_cart_to_rail.description")));
public static final BooleanSetting EXPLODING_CART_FIX = addSetting(new BooleanSetting("ExplodeRailsFix", false, Text.translatable("mendedminecarts.explode_rail_fix.description")));
public static final BooleanSetting NO_CART_ITEM_CAP = addSetting(new BooleanSetting("NoCartItemCap", false, Text.translatable("mendedminecarts.no_cart_item_cap.description")));
public static final BooleanSetting LAVA_CAULDRON_KILLS_TNT_CART = addSetting(new BooleanSetting("LavaCauldonKillsTNTCarts", false, Text.translatable("mendedminecarts.lava_cauldron_kills_tnt_carts")));

@Override
public void onInitialize() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package mendedminecarts.mixin;

import mendedminecarts.MendedMinecartsMod;
import net.minecraft.block.LavaCauldronBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.vehicle.TntMinecartEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.sound.SoundEvents;
import org.spongepowered.asm.mixin.Mixin;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LavaCauldronBlock.class)
public class LavaCauldronBlockMixin_TNTCartDamage {


@Redirect(
method = "onEntityCollision",
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setOnFireFromLava()V")
)
private void readCustomCount(Entity entity) {
if (MendedMinecartsMod.LAVA_CAULDRON_KILLS_TNT_CART.isEnabled()) {
if (entity instanceof TntMinecartEntity tntCart) {
this.setOnFireFromLava(tntCart);
return;
}
}
entity.setOnFireFromLava();
}

private void setOnFireFromLava(TntMinecartEntity tntCart) {
if (tntCart.isFireImmune()) {
return;
}
tntCart.setOnFireFor(15);
if (tntCart.damage(DamageSource.LAVA, 4.0f)) {
tntCart.playSound(SoundEvents.ENTITY_GENERIC_BURN, 0.4f, 2.0f + tntCart.getWorld().random.nextFloat() * 0.4f);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mendedminecarts.AbstractMinecartEntityAccess;
import mendedminecarts.MendedMinecartsMod;
import mendedminecarts.MinecartDisplayData;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.font.TextRenderer.TextLayerType;
import net.minecraft.client.render.VertexConsumerProvider;
Expand All @@ -29,7 +30,7 @@ protected MinecartEntityRendererMixin(EntityRendererFactory.Context ctx) {

@Inject(
method = "render(Lnet/minecraft/entity/vehicle/AbstractMinecartEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V",
at = @At("RETURN")
at = @At("HEAD")
)
private void renderInfo(T entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int light, CallbackInfo ci) {
if (MendedMinecartsMod.DISPLAY_CART_DATA.isEnabled() && entity instanceof AbstractMinecartEntityAccess entityAccess) {
Expand All @@ -53,13 +54,17 @@ private void renderInfo(T entity, float yaw, float tickDelta, MatrixStack matric
float f = entity.getHeight() + 0.5f;

float yOffset = 10 - (infoTexts.size() * 10);

float backgroundOpacity = MinecraftClient.getInstance().options.getTextBackgroundOpacity(0.25f);
int backgroundColor = (int)(backgroundOpacity * 255.0f) << 24;
for (Text infoText : infoTexts) {
matrices.push();
matrices.translate(0.0, f, 0.0);
matrices.multiply(this.dispatcher.getRotation());
matrices.scale(-0.025f, -0.025f, 0.025f);
Matrix4f matrix4f = matrices.peek().getPositionMatrix();
float h = -textRenderer.getWidth(infoText) / 2f;

textRenderer.draw(infoText, h, yOffset, -1, false, matrix4f, vertexConsumerProvider, TextLayerType.SEE_THROUGH, 0, light);

matrices.pop();
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/mendedminecarts/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
"mendedminecarts.hopper_locked": "Locked",
"mendedminecarts.wobble": "Wobble",
"mendedminecarts.is_rideable": "Rideable",
"mendedminecarts.no_cart_item_cap.description": "Remove the item cap of minecart inventories and item stacks. Adds a \"CustomCount\" integer attribute to the NBT of ItemStacks."
"mendedminecarts.no_cart_item_cap.description": "Remove the item cap of minecart inventories and item stacks. Adds a \"CustomCount\" integer attribute to the NBT of ItemStacks.",
"mendedminecarts.lava_cauldron_kills_tnt_carts": "Lava cauldrons don't make TNT carts explode."
}
1 change: 1 addition & 0 deletions src/main/resources/mendedminecarts.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"EntityShapeContextAccessor",
"EntityTrackerEntryMixin",
"ItemStackMixin_ItemCap",
"LavaCauldronBlockMixin_TNTCartDamage",
"MinecartEntityRendererMixin",
"StorageMinecartEntityMixin_ItemCap",
"TntMinecartEntityMixin",
Expand Down

0 comments on commit 0de165c

Please sign in to comment.