Skip to content

Commit

Permalink
优化掉头法杖及其他法杖代码的实现形式
Browse files Browse the repository at this point in the history
  • Loading branch information
YipKei committed Jul 19, 2024
1 parent 416dfdc commit d18a4ce
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,15 @@ protected void configure(RegistryWrapper.WrapperLookup arg) {
.add(Blocks.WHITE_WOOL)
;

getOrCreateTagBuilder(ModTags.Blocks.NETHER_BRICKS)
getOrCreateTagBuilder(ModTags.Blocks.NETHER_FORTRESS_CAN_SPAWNS)
.add(Blocks.NETHER_BRICKS)
.add(ModBlocks.NETHERRACK_SLAB)
.add(ModBlocks.NETHERRACK_STAIRS)
;

getOrCreateTagBuilder(ModTags.Blocks.BONE_MEAL_DROPS_EXTRA)
.add(Blocks.PITCHER_PLANT)
;

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.yipkei.vanilladdition.item;

import com.yipkei.vanilladdition.util.ModTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand All @@ -9,7 +8,6 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.block.Blocks;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.property.Properties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.yipkei.vanilladdition.item;

import com.yipkei.vanilladdition.util.ModTags;
import net.fabricmc.fabric.api.biome.v1.BiomeModificationContext;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

Expand Down
103 changes: 45 additions & 58 deletions src/main/java/com/yipkei/vanilladdition/item/MagicalGirlsWand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.yipkei.vanilladdition.item;

import com.yipkei.vanilladdition.util.Head;
import com.yipkei.vanilladdition.util.Heads;
import com.yipkei.vanilladdition.util.ModTags;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand All @@ -12,12 +11,8 @@
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.state.property.Properties;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

Expand All @@ -32,74 +27,66 @@ protected void replaceOrDrop(World world, BlockPos blockPos, BlockState blockSta
if ((blockState.isOf(Blocks.ZOMBIE_HEAD)) || (blockState.isOf(Blocks.ZOMBIE_WALL_HEAD))){
ItemStack playerHead = Head.getNewPlayerHead(player.getGameProfile(),"",1);
if (playerHead!=null){
ItemEntity playerHeadItem = new ItemEntity(world, blockPos.getX(),blockPos.getY(),blockPos.getZ(), playerHead);
playerHeadItem.setVelocity(0,0.5,0);
world.setBlockState(blockPos,Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL_AND_REDRAW);
world.spawnEntity(playerHeadItem);
spawnHead(world, blockPos, playerHead);
}
player.addStatusEffect(new StatusEffectInstance(RegistryEntry.of(StatusEffects.INSTANT_DAMAGE.value()),1,4));
return;
}
if (blockState.isOf(Blocks.REDSTONE_WIRE)){
int redstoneIndex;
if (blockState.getOrEmpty(Properties.POWER).isPresent()){
redstoneIndex = blockState.get(Properties.POWER);
ItemStack redstoneHead = Head.getTexturedHead("RedstoneHead_"+Integer.toHexString(redstoneIndex).toUpperCase(), Heads.redstoneHeadTextureList.get(redstoneIndex), Heads.redstoneHeadUUIDList.get(redstoneIndex),"", 1, MutableText.of(new TranslatableTextContent("RedstoneHead_",null,TranslatableTextContent.EMPTY_ARGUMENTS)).append(Integer.toHexString(redstoneIndex).toUpperCase()));
ItemEntity redstoneHeadItem = new ItemEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), redstoneHead);
redstoneHeadItem.setVelocity(0, 0.5, 0);
world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL_AND_REDRAW);
world.spawnEntity(redstoneHeadItem);
}
spawnHead(world, blockPos, Head.getPowerHead(blockState));
return;
}
if (blockState.isOf(Blocks.LAVA_CAULDRON)){
ItemStack lavaHead = Head.getTexturedHead(Registries.BLOCK.getId(Blocks.LAVA).getPath(), Heads.textureList.get(Blocks.LAVA_CAULDRON), Heads.uuidList.get(Blocks.LAVA_CAULDRON), "", 1, Blocks.LAVA.getName());
ItemEntity blockHeadItem = new ItemEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), lavaHead);
blockHeadItem.setVelocity(0, 0.5, 0);
world.setBlockState(blockPos, Blocks.CAULDRON.getDefaultState(), Block.NOTIFY_ALL_AND_REDRAW);
world.spawnEntity(blockHeadItem);
spawnHead(world, blockPos, Head.getBlockHead(Blocks.LAVA), Blocks.CAULDRON.getDefaultState());
return;
}
if (blockState.isOf(Blocks.WATER_CAULDRON) && blockState.get(Properties.LEVEL_3)==3){
spawnHead(world, blockPos, Head.getBlockHead(Blocks.WATER), Blocks.CAULDRON.getDefaultState());
return;
}
if (blockState.isOf(Blocks.WATER_CAULDRON)){
ItemStack waterHead = Head.getTexturedHead(Registries.BLOCK.getId(Blocks.WATER).getPath(), Heads.textureList.get(Blocks.WATER_CAULDRON), Heads.uuidList.get(Blocks.WATER_CAULDRON), "", 1, Blocks.WATER.getName());
ItemEntity blockHeadItem = new ItemEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), waterHead);
blockHeadItem.setVelocity(0, 0.5, 0);
world.setBlockState(blockPos, Blocks.CAULDRON.getDefaultState(), Block.NOTIFY_ALL_AND_REDRAW);
world.spawnEntity(blockHeadItem);
ItemStack head = Head.getBlockHead(blockState.getBlock());
if (head == null){
return;
}
Block block = blockState.getBlock();
if (Heads.uuidList.containsKey(block)) {
ItemStack blockHead = Head.getTexturedHead(Registries.BLOCK.getId(block).getPath(), Heads.textureList.get(block), Heads.uuidList.get(block), "", 1, block.getName());
ItemEntity blockHeadItem = new ItemEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), blockHead);
blockHeadItem.setVelocity(0, 0.5, 0);
if ((blockState.isOf(Blocks.BEDROCK)) || (blockState.isOf(Blocks.PISTON_HEAD) || (blockState.isOf(Blocks.REINFORCED_DEEPSLATE)))){
if (world.random.nextInt(10)>8){
world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL_AND_REDRAW);
world.spawnEntity(blockHeadItem);
}
player.addStatusEffect(new StatusEffectInstance(RegistryEntry.of(StatusEffects.INSTANT_DAMAGE.value()),1,20));
if (world.random.nextInt(10) == 0){
player.kill();
}
int chance = world.random.nextInt(10);
if ((blockState.isOf(Blocks.BEDROCK)) || (blockState.isOf(Blocks.PISTON_HEAD) || (blockState.isOf(Blocks.REINFORCED_DEEPSLATE)))){
if (chance == 0){
player.kill();
return;
}else if (chance > 8){
spawnHead(world, blockPos, head);
}
world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL_AND_REDRAW);
if (blockState.isOf(Blocks.TNT)){
if (world.random.nextInt(10)>8){
world.spawnEntity(blockHeadItem);
return;
}
TntEntity tntEntity = new TntEntity(world, (double)blockPos.getX() + 0.5, blockPos.getY(), (double)blockPos.getZ() + 0.5, player);
int i = tntEntity.getFuse();
tntEntity.setFuse((short)(world.random.nextInt(i / 4) + i / 8));
world.spawnEntity(tntEntity);
player.addStatusEffect(new StatusEffectInstance(RegistryEntry.of(StatusEffects.INSTANT_DAMAGE.value()),1,20));
return;
}
if (blockState.isOf(Blocks.TNT)){
if (chance > 8){
spawnHead(world, blockPos, head);
return;
}
if (blockState.isOf(Blocks.TURTLE_EGG)){
if (world.random.nextInt(10)<8){
return;
}
TntEntity tntEntity = new TntEntity(world, (double)blockPos.getX() + 0.5, blockPos.getY(), (double)blockPos.getZ() + 0.5, player);
int i = tntEntity.getFuse();
tntEntity.setFuse((short)(world.random.nextInt(i / 4) + i / 8));
world.spawnEntity(tntEntity);
return;
}
if (blockState.isOf(Blocks.TURTLE_EGG)){
if (chance <= 8 ){
world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL_AND_REDRAW);
return;
}
world.spawnEntity(blockHeadItem);
}
spawnHead(world,blockPos,head);
}

private static void spawnHead(World world, BlockPos pos, ItemStack head){
spawnHead(world, pos, head, Blocks.AIR.getDefaultState());
}

private static void spawnHead(World world, BlockPos pos, ItemStack head, BlockState blockState){
ItemEntity headEntity = new ItemEntity(world, pos.getX(), pos.getY(),pos.getZ(),head);
headEntity.setVelocity(0,0.5,0);
world.setBlockState(pos, blockState, Block.NOTIFY_ALL_AND_REDRAW);
world.spawnEntity(headEntity);
}
}
25 changes: 16 additions & 9 deletions src/main/java/com/yipkei/vanilladdition/util/Head.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import com.mojang.authlib.yggdrasil.ProfileResult;
import net.minecraft.component.Component;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.LoreComponent;
import net.minecraft.component.type.ProfileComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.property.Properties;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent;
import net.minecraft.util.Identifier;
import net.minecraft.util.UserCache;
import org.jetbrains.annotations.Nullable;

import java.util.List;

import java.util.Optional;
import java.util.UUID;

public abstract class Head {



public static ItemStack getNewPlayerHead(GameProfile gameProfile, String noteBlockSound, int count){
String playerName = gameProfile.getName();
PropertyMap propertyMap = gameProfile.getProperties();
Expand All @@ -42,10 +42,17 @@ public static ItemStack getNewPlayerHead(GameProfile gameProfile, String noteBlo
}
String textures = "ewogICJ0aW1lc3RhbXAiIDogMCwKICAicHJvZmlsZUlk" + texturePropertyValue.split("cHJvZmlsZUlk")[1];

ItemStack playerHeadStack = getTexturedHead(playerName, textures, gameProfile.getId(), noteBlockSound, count);
return getTexturedHead(playerName, textures, gameProfile.getId(), noteBlockSound, count);

return playerHeadStack;
}

public static ItemStack getPowerHead(BlockState blockState){
int power = blockState.get(Properties.POWER);
return getTexturedHead("Redstone_"+Integer.toHexString(power).toUpperCase(),Heads.getRedstoneHeadTexture(power),Heads.getRedstoneHeadUUID(power),"",1,MutableText.of(new TranslatableTextContent("RedstoneHead_",null,TranslatableTextContent.EMPTY_ARGUMENTS)).append(Integer.toHexString(power).toUpperCase()));
}

public static ItemStack getBlockHead(Block block){
return (Heads.isInList(block)) ? getTexturedHead(Registries.BLOCK.getId(block).getPath(), Heads.getBlockTexture(block), Heads.getBlockUUID(block),"", 1, block.getName()) : null;
}

public static ItemStack getTexturedHead(String entityName, String texture, UUID uuid, String noteBlockSound, int count){
Expand Down
Loading

0 comments on commit d18a4ce

Please sign in to comment.