-
Notifications
You must be signed in to change notification settings - Fork 0
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
7e19612
commit 86e02bf
Showing
40 changed files
with
2,155 additions
and
54 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
7 changes: 6 additions & 1 deletion
7
src/main/java/com/equilibrium/MITEequilibriumDataGenerator.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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
package com.equilibrium; | ||
|
||
import com.equilibrium.gen.ModRecipeGenerator; | ||
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; | ||
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; | ||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider; | ||
import net.minecraft.data.DataGenerator; | ||
|
||
public class MITEequilibriumDataGenerator implements DataGeneratorEntrypoint { | ||
@Override | ||
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { | ||
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator){ | ||
FabricDataGenerator.Pack pack=fabricDataGenerator.createPack(); | ||
pack.addProvider(ModRecipeGenerator::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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.equilibrium.block; | ||
|
||
|
||
import net.minecraft.block.*; | ||
import net.minecraft.block.piston.PistonBehavior; | ||
import net.minecraft.item.BlockItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.sound.BlockSoundGroup; | ||
import net.minecraft.util.Identifier; | ||
|
||
import static net.minecraft.block.Blocks.register; | ||
|
||
public class ModBlocks { | ||
|
||
public static final Block EXAMPLE_BLOCK = new Block(Block.Settings.create().strength(4.0f)); | ||
//strength中第一个为硬度,第二个为爆炸抗性 | ||
public static final Block UNDERWORLD_PORTAL = | ||
new UnderworldPortalBlock( | ||
AbstractBlock.Settings.create() | ||
.noCollision() | ||
.ticksRandomly() | ||
.strength(-1.0F) | ||
.sounds(BlockSoundGroup.GLASS) | ||
.luminance(state -> 11) | ||
.pistonBehavior(PistonBehavior.BLOCK) | ||
); | ||
public static final Block OVERWORLD_PORTAL = | ||
new UnderworldPortalBlock( | ||
AbstractBlock.Settings.create() | ||
.noCollision() | ||
.ticksRandomly() | ||
.strength(-1.0F) | ||
.sounds(BlockSoundGroup.GLASS) | ||
.luminance(state -> 11) | ||
.pistonBehavior(PistonBehavior.BLOCK) | ||
); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
public static void registerModBlocks(){ | ||
Registry.register(Registries.BLOCK, Identifier.of("miteequilibrium", "example_block"), EXAMPLE_BLOCK); | ||
Registry.register(Registries.ITEM, Identifier.of("miteequilibrium", "example_block"), new BlockItem(EXAMPLE_BLOCK, new Item.Settings())); | ||
|
||
Registry.register(Registries.BLOCK, Identifier.of("miteequilibrium", "underworld_portalblock"), UNDERWORLD_PORTAL); | ||
Registry.register(Registries.ITEM, Identifier.of("miteequilibrium", "underworld_portalblock"), new BlockItem(UNDERWORLD_PORTAL, new Item.Settings())); | ||
|
||
Registry.register(Registries.BLOCK, Identifier.of("miteequilibrium", "overworld_portalblock"), OVERWORLD_PORTAL); | ||
Registry.register(Registries.ITEM, Identifier.of("miteequilibrium", "overworld_portalblock"), new BlockItem(OVERWORLD_PORTAL, new Item.Settings())); | ||
|
||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
src/main/java/com/equilibrium/block/OverworldPortalBlock.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,107 @@ | ||
package com.equilibrium.block; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Portal; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.particle.ParticleTypes; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.world.GameRules; | ||
import net.minecraft.world.TeleportTarget; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.border.WorldBorder; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class OverworldPortalBlock extends Block implements Portal { | ||
public OverworldPortalBlock(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public int getPortalDelay(ServerWorld world, Entity entity) { | ||
return entity instanceof PlayerEntity playerEntity | ||
? Math.max( | ||
1, | ||
world.getGameRules() | ||
.getInt(playerEntity.getAbilities().invulnerable ? GameRules.PLAYERS_NETHER_PORTAL_CREATIVE_DELAY : GameRules.PLAYERS_NETHER_PORTAL_DEFAULT_DELAY) | ||
) | ||
: 0; | ||
} | ||
|
||
|
||
@Override | ||
public TeleportTarget createTeleportTarget(ServerWorld world, Entity entity, BlockPos pos) { | ||
//获取你的现有维度 | ||
RegistryKey<World> currentDimensionKey = world.getRegistryKey(); | ||
|
||
//注册自定义维度 | ||
RegistryKey<World> customDimensionKey = RegistryKey.of(RegistryKeys.WORLD, Identifier.of("miteequilibrium", "underworld")); | ||
//创建自定义维度世界实例 | ||
ServerWorld serverWorld = world.getServer().getWorld(customDimensionKey); | ||
if (serverWorld!=null){ | ||
System.out.println("weelll"); | ||
}else{ | ||
System.out.println("no!"); | ||
} | ||
//当自定义维度存在时(否则会产生空指针错误): | ||
//世界边界限制器 | ||
WorldBorder worldBorder = serverWorld.getWorldBorder(); | ||
//1倍放大,参考下界是8倍 | ||
BlockPos Pos = worldBorder.clamp(entity.getX() * 1, entity.getY(), entity.getZ() * 1); | ||
|
||
TeleportTarget.PostDimensionTransition postTransition = TeleportTarget.SEND_TRAVEL_THROUGH_PORTAL_PACKET; | ||
|
||
return TeleportTarget.missingSpawnBlock(serverWorld, entity, postTransition); | ||
} | ||
|
||
|
||
protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { | ||
if (entity.canUsePortals(false)) { | ||
entity.tryUsePortal(this, pos); | ||
} | ||
} | ||
@Override | ||
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) { | ||
if (random.nextInt(100) == 0) { | ||
world.playSound( | ||
(double)pos.getX() + 0.5, | ||
(double)pos.getY() + 0.5, | ||
(double)pos.getZ() + 0.5, | ||
SoundEvents.BLOCK_PORTAL_AMBIENT, | ||
SoundCategory.BLOCKS, | ||
0.5F, | ||
random.nextFloat() * 0.4F + 0.8F, | ||
false | ||
); | ||
} | ||
|
||
for (int i = 0; i < 4; i++) { | ||
double d = (double)pos.getX() + random.nextDouble(); | ||
double e = (double)pos.getY() + random.nextDouble(); | ||
double f = (double)pos.getZ() + random.nextDouble(); | ||
double g = ((double)random.nextFloat() - 0.5) * 0.5; | ||
double h = ((double)random.nextFloat() - 0.5) * 0.5; | ||
double j = ((double)random.nextFloat() - 0.5) * 0.5; | ||
int k = random.nextInt(2) * 2 - 1; | ||
if (!world.getBlockState(pos.west()).isOf(this) && !world.getBlockState(pos.east()).isOf(this)) { | ||
d = (double)pos.getX() + 0.5 + 0.25 * (double)k; | ||
g = (double)(random.nextFloat() * 2.0F * (float)k); | ||
} else { | ||
f = (double)pos.getZ() + 0.5 + 0.25 * (double)k; | ||
j = (double)(random.nextFloat() * 2.0F * (float)k); | ||
} | ||
|
||
world.addParticle(ParticleTypes.PORTAL, d, e, f, g, h, j); | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.