Skip to content

Commit

Permalink
Blocks and gui utils modules
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaMode committed Apr 7, 2024
1 parent 8538ba3 commit 7cf7f64
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Just choose a version and use its version number.
| `accessors` | Accessor mixins aplenty |
| `attributes` | Additional Entity Attributes; step height, gravity, swim speed |
| `base` | Code that has not yet been split into modules |
| `blocks` | Adds extra block extensions. |
| `brewing` | A potion recipe api |
| `client_events` | Useful client-side events |
| `common` | Miscellaneous utilities for other modules |
Expand All @@ -34,6 +35,7 @@ Just choose a version and use its version number.
| `extensions` | Extensions to vanilla classes for additional functionality |
| `fluids` | Api that provides additional fluid attributes for fluids |
| `gametest` | Tools to make GameTest creation as easy as possible |
| `gui_utils` | Adds additional utility classes and methods for screens and guis |
| `items` | Adds extra item extensions |
| `lazy_registration` | A implementation of forge's DeferredRegister system rewritten for fabric |
| `level_events` | Provides common level events for mods. |
Expand Down
Empty file added modules/blocks/build.gradle
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.fabricators_of_create.porting_lib.blocks.extensions;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;

public interface OnExplodedBlock {
/**
* Called when the block is destroyed by an explosion.
* Useful for allowing the block to take into account tile entities,
* state, etc. when exploded, before it is removed.
*
* @param level The current level
* @param pos Block position in level
* @param explosion The explosion instance affecting the block
*/
default void onBlockExploded(BlockState state, Level level, BlockPos pos, Explosion explosion) {
level.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
((Block) this).wasExploded(level, pos, explosion);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.fabricators_of_create.porting_lib.blocks.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;

import io.github.fabricators_of_create.porting_lib.blocks.extensions.OnExplodedBlock;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;

@Mixin(Explosion.class)
public class ExplosionMixin {
@WrapOperation(method = "finalizeExplosion", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;wasExploded(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/Explosion;)V"))
private void onBlockExploded(Block instance, Level level, BlockPos blockPos, Explosion explosion, Operation<Void> original, @Local(index = 7) BlockState state) {
if (state.getBlock() instanceof OnExplodedBlock onExplodedBlock) {
onExplodedBlock.onBlockExploded(state, level, blockPos, explosion);
} else {
original.call(instance, level, blockPos, explosion);
}
}

@WrapWithCondition(method = "finalizeExplosion", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z"))
private boolean dontSetBlockOnCustom(Level level, BlockPos pos, BlockState airState, int flag, @Local(index = 7) BlockState state) {
if (state.getBlock() instanceof OnExplodedBlock)
return false;
return true;
}
}
7 changes: 7 additions & 0 deletions modules/blocks/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"schemaVersion": 1,
"id": "porting_lib_blocks",
"version": "${version}",
"name": "Porting Lib Blocks",
"description": "Adds extra block extensions."
}
12 changes: 12 additions & 0 deletions modules/blocks/src/main/resources/porting_lib_blocks.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "io.github.fabricators_of_create.porting_lib.blocks.mixin",
"compatibilityLevel": "JAVA_17",
"injectors": {
"defaultRequire": 1
},
"mixins": [
"ExplosionMixin"
]
}
Empty file added modules/gui_utils/build.gradle
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.fabricators_of_create.porting_lib.gui.utils;

import net.minecraft.client.gui.components.Button;

public class ModdedButton extends Button {
protected ModdedButton(Builder builder) {
super(builder.x, builder.y, builder.width, builder.height, builder.message, builder.onPress, builder.createNarration);
setTooltip(builder.tooltip); // Forge: Make use of the Builder tooltip
}
}
7 changes: 7 additions & 0 deletions modules/gui_utils/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"schemaVersion": 1,
"id": "porting_lib_gui_utils",
"version": "${version}",
"name": "Porting Lib Gui Utils",
"description": "Adds additional utility classes and methods for screens and guis."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
accessWidener v2 named
accessible field net/minecraft/client/gui/components/Button$Builder message Lnet/minecraft/network/chat/Component;
accessible field net/minecraft/client/gui/components/Button$Builder onPress Lnet/minecraft/client/gui/components/Button$OnPress;
accessible field net/minecraft/client/gui/components/Button$Builder tooltip Lnet/minecraft/client/gui/components/Tooltip;
accessible field net/minecraft/client/gui/components/Button$Builder x I
accessible field net/minecraft/client/gui/components/Button$Builder y I
accessible field net/minecraft/client/gui/components/Button$Builder width I
accessible field net/minecraft/client/gui/components/Button$Builder height I
accessible field net/minecraft/client/gui/components/Button$Builder createNarration Lnet/minecraft/client/gui/components/Button$CreateNarration;

0 comments on commit 7cf7f64

Please sign in to comment.