-
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
eb1ebc5
commit a444cde
Showing
21 changed files
with
441 additions
and
25 deletions.
There are no files selected for viewing
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
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
53 changes: 53 additions & 0 deletions
53
...ava/info/partonetrain/botaniacombat/render/block_entity/AngryBozuBlockEntityRenderer.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,53 @@ | ||
package info.partonetrain.botaniacombat.render.block_entity; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import info.partonetrain.botaniacombat.BotaniaCombat; | ||
import info.partonetrain.botaniacombat.block.block_entity.AngryBozuBlockEntity; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; | ||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; | ||
import net.minecraft.resources.ResourceLocation; | ||
import vazkii.botania.client.core.handler.ClientTickHandler; | ||
import vazkii.botania.client.model.BotaniaModelLayers; | ||
import vazkii.botania.client.model.TeruTeruBozuModel; | ||
import vazkii.botania.client.render.block_entity.TeruTeruBozuBlockEntityRenderer; | ||
import vazkii.botania.common.helper.VecHelper; | ||
|
||
import java.util.Random; | ||
|
||
import static vazkii.botania.client.core.handler.ClientTickHandler.partialTicks; | ||
|
||
public class AngryBozuBlockEntityRenderer implements BlockEntityRenderer<AngryBozuBlockEntity> { | ||
|
||
private static final ResourceLocation texture = new ResourceLocation(BotaniaCombat.MOD_ID, "textures/model/angry_bozu.png"); | ||
private final TeruTeruBozuModel model; | ||
|
||
public AngryBozuBlockEntityRenderer(BlockEntityRendererProvider.Context ctx){ | ||
model = new TeruTeruBozuModel(ctx.bakeLayer(BotaniaModelLayers.TERU_TERU_BOZU)); | ||
} | ||
|
||
@Override | ||
public void render(AngryBozuBlockEntity blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource buffer, int packedLight, int packedOverlay) { | ||
poseStack.pushPose(); | ||
poseStack.mulPose(VecHelper.rotateX(180)); | ||
double time = ClientTickHandler.ticksInGame + partialTicks; | ||
boolean hasWorld = blockEntity != null && blockEntity.getLevel() != null; | ||
poseStack.translate(0.5F, -1.5F, -0.5F); | ||
if (hasWorld) { | ||
poseStack.mulPose(VecHelper.rotateY((float) (time * 0.3))); | ||
float rotZ = 4F * (float) Math.sin(time * 0.05F); | ||
//"rage" | ||
if(time % 10 == 0 || time % 10 == 2 || time % 10 == 4){ | ||
rotZ -= 1; | ||
}else if(time % 10 == 1 || time % 10 == 3 || time % 10 == 5){ | ||
rotZ += 1; | ||
} | ||
poseStack.mulPose(VecHelper.rotateZ(rotZ)); | ||
} | ||
|
||
VertexConsumer vertexConsumer = buffer.getBuffer(model.renderType(texture)); | ||
model.renderToBuffer(poseStack, vertexConsumer, packedLight, packedOverlay, 1, 1, 1, 1); | ||
poseStack.popPose(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ient/java/info/partonetrain/botaniacombat/render/entity/BotaniaCombatEntityRenderers.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,12 @@ | ||
package info.partonetrain.botaniacombat.render.entity; | ||
|
||
import info.partonetrain.botaniacombat.registry.BotaniaCombatBlockEntities; | ||
import info.partonetrain.botaniacombat.render.block_entity.AngryBozuBlockEntityRenderer; | ||
import vazkii.botania.client.render.entity.EntityRenderers; | ||
|
||
public class BotaniaCombatEntityRenderers { | ||
public static void registerBlockEntityRenderers(EntityRenderers.BERConsumer consumer) { | ||
consumer.register(BotaniaCombatBlockEntities.ANGRY_BOZU, AngryBozuBlockEntityRenderer::new); | ||
} | ||
|
||
} |
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
90 changes: 90 additions & 0 deletions
90
src/main/java/info/partonetrain/botaniacombat/block/AngryBozuBlock.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,90 @@ | ||
package info.partonetrain.botaniacombat.block; | ||
|
||
import info.partonetrain.botaniacombat.block.block_entity.AngryBozuBlockEntity; | ||
import info.partonetrain.botaniacombat.registry.BotaniaCombatBlockEntities; | ||
import net.minecraft.commands.Commands; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.item.ItemEntity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.EntityBlock; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntityTicker; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import vazkii.botania.common.block.TeruTeruBozuBlock; | ||
import vazkii.botania.common.helper.EntityHelper; | ||
|
||
public class AngryBozuBlock extends TeruTeruBozuBlock implements EntityBlock { | ||
public AngryBozuBlock(Properties builder) { | ||
super(builder); | ||
} | ||
|
||
@Override | ||
public void entityInside(BlockState state, Level world, BlockPos pos, Entity e) { | ||
if (!world.isClientSide && e instanceof ItemEntity item) { | ||
ItemStack stack = item.getItem(); | ||
if (isWitherRose(stack) && startThunder(world)) { | ||
EntityHelper.shrinkItem(item); | ||
return; | ||
} | ||
} | ||
super.entityInside(state, world, pos, e); | ||
} | ||
|
||
@Override | ||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { | ||
ItemStack stack = player.getItemInHand(hand); | ||
if (!stack.isEmpty() && (isWitherRose(stack) && startThunder(world))) { | ||
if (!player.getAbilities().instabuild) { | ||
stack.shrink(1); | ||
} | ||
return InteractionResult.sidedSuccess(world.isClientSide()); | ||
} | ||
return super.use(state, world, pos, player, hand, hit); | ||
} | ||
|
||
private boolean isWitherRose(ItemStack stack) { | ||
return stack.is(Blocks.WITHER_ROSE.asItem()); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { | ||
return new AngryBozuBlockEntity(pos, state); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) { | ||
if (!level.isClientSide) { | ||
return createTickerHelper(type, BotaniaCombatBlockEntities.ANGRY_BOZU, AngryBozuBlockEntity::serverTick); | ||
} | ||
return null; | ||
} | ||
|
||
private boolean startThunder(Level world) { | ||
if (!world.isThundering()) { | ||
if(!world.isRaining()){ | ||
world.getLevelData().setRaining(true); | ||
} | ||
AngryBozuBlockEntity.resetThunderTime(world); //this is what actually makes it thunder | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { | ||
return world.isThundering() ? 15 : 0; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/info/partonetrain/botaniacombat/block/block_entity/AngryBozuBlockEntity.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,34 @@ | ||
package info.partonetrain.botaniacombat.block.block_entity; | ||
|
||
import info.partonetrain.botaniacombat.registry.BotaniaCombatBlockEntities; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.storage.LevelData; | ||
import net.minecraft.world.level.storage.ServerLevelData; | ||
import vazkii.botania.common.block.block_entity.BotaniaBlockEntity; | ||
|
||
public class AngryBozuBlockEntity extends BotaniaBlockEntity { | ||
private boolean wasThundering = false; | ||
public AngryBozuBlockEntity(BlockPos pos, BlockState state) { | ||
super(BotaniaCombatBlockEntities.ANGRY_BOZU, pos, state); | ||
} | ||
|
||
public static void serverTick(Level level, BlockPos worldPosition, BlockState state, AngryBozuBlockEntity self) { | ||
boolean isThundering = level.isThundering(); | ||
|
||
if (self.wasThundering != isThundering) { | ||
level.updateNeighbourForOutputSignal(worldPosition, state.getBlock()); | ||
} | ||
self.wasThundering = isThundering; | ||
} | ||
|
||
public static void resetThunderTime(Level w) { //sets how long the thunder will last | ||
int time = w.random.nextInt(w.getLevelData().isRaining() ? 12000 : 168000) + 12000; | ||
if(w instanceof ServerLevel sl){ | ||
sl.setWeatherParameters(0, time, true, true); | ||
//setWeatherParameters sets LevelData | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/info/partonetrain/botaniacombat/registry/BotaniaCombatBlockEntities.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,25 @@ | ||
package info.partonetrain.botaniacombat.registry; | ||
|
||
import info.partonetrain.botaniacombat.BotaniaCombat; | ||
import info.partonetrain.botaniacombat.block.block_entity.AngryBozuBlockEntity; | ||
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
public class BotaniaCombatBlockEntities { | ||
|
||
public static final BlockEntityType<AngryBozuBlockEntity> ANGRY_BOZU = registerBlockEntity("angry_bozu.json", AngryBozuBlockEntity::new); | ||
|
||
public static void init() {} | ||
|
||
public static <T extends BlockEntity> BlockEntityType<T> registerBlockEntity(String name, BiFunction<BlockPos, BlockState, T> func) { | ||
return Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, new ResourceLocation(BotaniaCombat.MOD_ID, name), FabricBlockEntityTypeBuilder.create(func::apply, BotaniaCombatBlocks.angryBozu).build()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/info/partonetrain/botaniacombat/registry/BotaniaCombatBlocks.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,35 @@ | ||
package info.partonetrain.botaniacombat.registry; | ||
|
||
import info.partonetrain.botaniacombat.BotaniaCombat; | ||
import info.partonetrain.botaniacombat.block.AngryBozuBlock; | ||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.BlockItem; | ||
import net.minecraft.world.item.DyeColor; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.SoundType; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument; | ||
import vazkii.botania.api.BotaniaRegistries; | ||
import vazkii.botania.common.item.block.BlockItemWithSpecialRenderer; | ||
|
||
public class BotaniaCombatBlocks { | ||
|
||
public static final Block angryBozu = registerBlock ("angry_bozu", new AngryBozuBlock(BlockBehaviour.Properties.of().sound(SoundType.WOOL).instrument(NoteBlockInstrument.GUITAR).mapColor(DyeColor.RED))); | ||
|
||
public static void init() {} | ||
|
||
public static <T extends Block> T registerBlock(String name, T block) { | ||
ResourceLocation id = new ResourceLocation(BotaniaCombat.MOD_ID, name); | ||
Registry.register(BuiltInRegistries.BLOCK, id, block); | ||
BlockItem blockItem = new BlockItemWithSpecialRenderer(block, new Item.Properties()); | ||
Registry.register(BuiltInRegistries.ITEM, id, blockItem); | ||
|
||
ItemGroupEvents.modifyEntriesEvent(BotaniaRegistries.BOTANIA_TAB_KEY).register(entries -> entries.accept(block.asItem())); | ||
|
||
return block; | ||
} | ||
} |
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
Oops, something went wrong.