Skip to content

Commit

Permalink
Add Visual Hopper Cart Locking
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Dec 18, 2023
1 parent f51d486 commit 35ca8ee
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/mendedminecarts/MendedMinecartsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static <T extends Setting> T addSetting(T setting) {
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.description")));
public static final BooleanSetting RAIL_PLACEMENT = addSetting(new BooleanSetting("RailPlacement", false, Text.translatable("mendedminecarts.rail_placement.description")));
public static final BooleanSetting VISUAL_HOPPER_CART_LOCKING = addSetting(new BooleanSetting("VisualHopperCartLocking", false, Text.translatable("mendedminecarts.visual_hopper_cart_locking.description")));

@Override
public void onInitialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void updateDisplayInfo(CallbackInfo ci) {
if (!this.getWorld().isClient()) {
return;
}
if (MendedMinecartsMod.DISPLAY_CART_DATA.isEnabled() &&
if ((MendedMinecartsMod.DISPLAY_CART_DATA.isEnabled() || MendedMinecartsMod.VISUAL_HOPPER_CART_LOCKING.isEnabled()) &&
MinecraftClient.getInstance().player != null &&
MinecraftClient.getInstance().player.hasPermissionLevel(2) &&
MinecraftClient.getInstance().player.getPos().squaredDistanceTo(this.getPos()) < MendedMinecartsMod.DATA_RENDER_DISTANCE_SQ) {
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/mendedminecarts/mixin/HopperMinecartEntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package mendedminecarts.mixin;

import mendedminecarts.AbstractMinecartEntityAccess;
import mendedminecarts.MendedMinecartsMod;
import mendedminecarts.MinecartDisplayData;
import net.minecraft.block.BlockState;
import net.minecraft.block.HopperBlock;
import net.minecraft.entity.vehicle.HopperMinecartEntity;
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;

@Mixin(HopperMinecartEntity.class)
public class HopperMinecartEntityMixin {

@Inject(
method = "getDefaultContainedBlock", at = @At("RETURN"), cancellable = true
)
private void displayLockedHopperWhenLocked(CallbackInfoReturnable<BlockState> cir) {
if (MendedMinecartsMod.VISUAL_HOPPER_CART_LOCKING.isEnabled() && this instanceof AbstractMinecartEntityAccess entityAccess) {
MinecartDisplayData displayInfo = entityAccess.getDisplayInfo();
if (displayInfo == null) {
return;
}
if (displayInfo.hopperLocked()) {
BlockState disabledHopper = cir.getReturnValue();
disabledHopper = disabledHopper.withIfExists(HopperBlock.ENABLED, false);
cir.setReturnValue(disabledHopper);
}

}
}

@Inject(
method = "getDefaultBlockOffset", at = @At("RETURN"), cancellable = true
)
private void displayHopperLowerWhenLocked(CallbackInfoReturnable<Integer> cir) {
if (MendedMinecartsMod.VISUAL_HOPPER_CART_LOCKING.isEnabled() && this instanceof AbstractMinecartEntityAccess entityAccess) {
MinecartDisplayData displayInfo = entityAccess.getDisplayInfo();
if (displayInfo == null) {
return;
}
if (displayInfo.hopperLocked()) {
cir.setReturnValue(-1);
}

}
}
}
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 @@ -48,5 +48,6 @@
"mendedminecarts.lava_cauldron_kills_tnt_carts.description": "Lava cauldrons don't make TNT carts explode.",
"mendedminecarts.rail_placement.description": "Better rail placement when player is sneaking. Sloped rails like top slabs, curved rails when clicking in the corner of a block.",
"mendedminecarts.fuse.description": "Displays the fuse time of TNT minecarts.",
"mendedminecarts.fuse": "Fuse"
"mendedminecarts.fuse": "Fuse",
"mendedminecarts.visual_hopper_cart_locking.description": "Locked hopper carts have locked hopper blocks inside them. Requires a texture pack to make visible."
}
1 change: 1 addition & 0 deletions src/main/resources/mendedminecarts.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"DataQueryHandlerMixin",
"EntityShapeContextAccessor",
"EntityTrackerEntryMixin",
"HopperMinecartEntityMixin",
"ItemStackMixin_ItemCap",
"LavaCauldronBlockMixin_TNTCartDamage",
"MinecartEntityRendererMixin",
Expand Down

0 comments on commit 35ca8ee

Please sign in to comment.