Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lithewings committed Jul 7, 2024
1 parent 7e19612 commit 1484663
Show file tree
Hide file tree
Showing 41 changed files with 2,265 additions and 54 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ repositories {
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}
loom {
accessWidenerPath = file("src/main/resources/name.accesswidener")
}

fabricApi {
configureDataGeneration()
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/equilibrium/MITEequilibrium.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.equilibrium;

import com.equilibrium.block.ModBlocksTest;
import com.equilibrium.block.ModBlocks;

import com.equilibrium.item.Ingots;
import com.equilibrium.item.ModItemGroup;
import com.equilibrium.item.ModItems;
Expand All @@ -9,6 +10,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.equilibrium.worldgen.ModOreGenerator.registerModOre;


public class MITEequilibrium implements ModInitializer {

Expand All @@ -28,7 +31,7 @@ public void onInitialize() {
//物品添加测试
ModItems.registerModItemTest();
//方块添加测试
ModBlocksTest.registerModBlocks();
ModBlocks.registerModBlocks();

//以下开始正式添加物品:

Expand All @@ -38,7 +41,9 @@ public void onInitialize() {
//添加锭
Ingots.registerModItemIngots();

//注册矿物

registerModOre();



Expand Down
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);

}
}
60 changes: 60 additions & 0 deletions src/main/java/com/equilibrium/block/ModBlocks.java
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()));


}
}
36 changes: 0 additions & 36 deletions src/main/java/com/equilibrium/block/ModBlocksTest.java

This file was deleted.

107 changes: 107 additions & 0 deletions src/main/java/com/equilibrium/block/OverworldPortalBlock.java
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);
}
}


}
Loading

0 comments on commit 1484663

Please sign in to comment.