-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f12dd8a
commit d3b3e2c
Showing
28 changed files
with
536 additions
and
3 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/main/java/ru/pinkgoosik/hiddenrealm/block/LunarFlagBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package ru.pinkgoosik.hiddenrealm.block; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.ShapeContext; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.EnumProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.function.BooleanBiFunction; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.util.shape.VoxelShapes; | ||
import net.minecraft.world.BlockView; | ||
|
||
public class LunarFlagBlock extends Block { | ||
public static final EnumProperty<Direction.Axis> AXIS = Properties.HORIZONTAL_AXIS; | ||
|
||
private static final VoxelShape X_SHAPE = createXShape(); | ||
private static final VoxelShape Z_SHAPE = createZShape(); | ||
|
||
public LunarFlagBlock(Settings settings) { | ||
super(settings); | ||
this.setDefaultState(this.stateManager.getDefaultState().with(AXIS, Direction.Axis.X)); | ||
} | ||
|
||
private static VoxelShape createZShape() { | ||
VoxelShape shape = VoxelShapes.empty(); | ||
shape = VoxelShapes.combine(shape, VoxelShapes.cuboid(0.4375, 0.6875, 0, 0.5625, 0.875, 1), BooleanBiFunction.OR); | ||
return shape; | ||
} | ||
|
||
private static VoxelShape createXShape() { | ||
VoxelShape shape = VoxelShapes.empty(); | ||
shape = VoxelShapes.combine(shape, VoxelShapes.cuboid(0, 0.6875, 0.4375, 1, 0.875, 0.5625), BooleanBiFunction.OR); | ||
return shape; | ||
} | ||
|
||
@Override | ||
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { | ||
return state.get(AXIS).equals(Direction.Axis.Z) ? Z_SHAPE : X_SHAPE; | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
builder.add(AXIS); | ||
} | ||
|
||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
if(ctx.getSide().getAxis().isHorizontal()) { | ||
return this.getDefaultState().with(AXIS, ctx.getSide().getAxis()); | ||
} | ||
else return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/ru/pinkgoosik/hiddenrealm/extension/LivingEntityExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ru.pinkgoosik.hiddenrealm.extension; | ||
|
||
public interface LivingEntityExtension { | ||
boolean isBeheaded(); | ||
void setBeheaded(boolean isBeheaded); | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/ru/pinkgoosik/hiddenrealm/mixin/BipedEntityModelMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ru.pinkgoosik.hiddenrealm.mixin; | ||
|
||
import net.minecraft.client.model.ModelPart; | ||
import net.minecraft.client.render.entity.model.AnimalModel; | ||
import net.minecraft.client.render.entity.model.BipedEntityModel; | ||
import net.minecraft.client.render.entity.model.ModelWithArms; | ||
import net.minecraft.client.render.entity.model.ModelWithHead; | ||
import net.minecraft.entity.LivingEntity; | ||
import org.spongepowered.asm.mixin.Final; | ||
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.callback.CallbackInfo; | ||
import ru.pinkgoosik.hiddenrealm.extension.LivingEntityExtension; | ||
|
||
@Mixin(BipedEntityModel.class) | ||
abstract class BipedEntityModelMixin<T extends LivingEntity> extends AnimalModel<T> implements ModelWithArms, ModelWithHead { | ||
|
||
@Shadow | ||
@Final | ||
public ModelPart head; | ||
|
||
@Inject(method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V", at = @At("HEAD")) | ||
void setAngles(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) { | ||
if(livingEntity instanceof LivingEntityExtension ex) { | ||
head.visible = !ex.isBeheaded(); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/ru/pinkgoosik/hiddenrealm/mixin/LivingEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package ru.pinkgoosik.hiddenrealm.mixin; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.entity.data.DataTracker; | ||
import net.minecraft.entity.data.TrackedData; | ||
import net.minecraft.entity.data.TrackedDataHandlerRegistry; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.world.World; | ||
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.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
import ru.pinkgoosik.hiddenrealm.extension.LivingEntityExtension; | ||
import ru.pinkgoosik.hiddenrealm.registry.HiddenRealmItems; | ||
|
||
@Mixin(LivingEntity.class) | ||
abstract class LivingEntityMixin extends Entity implements LivingEntityExtension { | ||
|
||
private static final TrackedData<Boolean> BEHEADED = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.BOOLEAN); | ||
|
||
public LivingEntityMixin(EntityType<?> type, World world) { | ||
super(type, world); | ||
} | ||
|
||
@Inject(method = "writeCustomDataToNbt", at = @At(value = "TAIL")) | ||
public void writeCustomDataToNBT(NbtCompound nbt, CallbackInfo ci){ | ||
nbt.putBoolean("Beheaded", this.isBeheaded()); | ||
} | ||
|
||
@Inject(method = "readCustomDataFromNbt", at = @At(value = "TAIL")) | ||
public void readCustomDataToNBT(NbtCompound nbt, CallbackInfo ci){ | ||
this.setBeheaded(nbt.getBoolean("Beheaded")); | ||
} | ||
|
||
@Inject(method = "initDataTracker", at = @At(value = "TAIL")) | ||
public void initDataTracker(DataTracker.Builder builder, CallbackInfo ci) { | ||
builder.add(BEHEADED, false); | ||
} | ||
|
||
@Inject(method = "damage", at = @At("HEAD")) | ||
void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) { | ||
|
||
if(source.getAttacker() instanceof PlayerEntity player) { | ||
if(player.getStackInHand(Hand.MAIN_HAND).isOf(HiddenRealmItems.BEHEADING_KATANA) && !isBeheaded()) { | ||
setBeheaded(true); | ||
dropStack(Items.ZOMBIE_HEAD.getDefaultStack()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isBeheaded() { | ||
return dataTracker.get(BEHEADED); | ||
} | ||
|
||
@Override | ||
public void setBeheaded(boolean isBeheaded) { | ||
dataTracker.set(BEHEADED, isBeheaded); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/resources/assets/hiddenrealm/blockstates/lunar_flag.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"variants": { | ||
"axis=x": { | ||
"model": "hiddenrealm:block/lunar_flag" | ||
}, | ||
"axis=z": { | ||
"model": "hiddenrealm:block/lunar_flag", | ||
"y": 90 | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/resources/assets/hiddenrealm/blockstates/mossy_moonstone_brick_slab.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"variants": { | ||
"type=bottom": { | ||
"model": "hiddenrealm:block/mossy_moonstone_brick_slab" | ||
}, | ||
"type=double": { | ||
"model": "hiddenrealm:block/mossy_moonstone_bricks" | ||
}, | ||
"type=top": { | ||
"model": "hiddenrealm:block/mossy_moonstone_brick_slab_top" | ||
} | ||
} | ||
} |
Oops, something went wrong.