Skip to content

Commit

Permalink
Update to 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugman76 committed Jun 28, 2023
1 parent 8d92eb0 commit 3dd6b5b
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 148 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ loader_name=Fabric
loader_icon=https://fabricmc.net/assets/logo.png

# check these on https://fabricmc.net/versions.html
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.5
loader_version=0.14.12
fabric_version=0.72.0+1.19.3
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.8
loader_version=0.14.21
fabric_version=0.84.0+1.20.1

# https://github.com/DawnTeamMC/DawnAPI
dawn_version=4.1.0
dawn_version=5.0.0
212 changes: 104 additions & 108 deletions src/main/java/fr/hugman/mubble/block/BeepBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import fr.hugman.dawn.block.DawnBlockSettings;
import fr.hugman.mubble.world.MubbleGamerules;
import net.minecraft.SharedConstants;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.MapColor;
import net.minecraft.block.Material;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.*;
import net.minecraft.entity.EntityType;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.server.world.ServerWorld;
Expand All @@ -29,107 +25,107 @@
* @since v4.0.0
*/
public class BeepBlock extends Block {
public static final int DEFAULT_COOLDOWN = SharedConstants.TICKS_PER_SECOND * 4;
public static final BooleanProperty FRAME = BooleanProperty.of("frame");

public final boolean offset;

public BeepBlock(Settings settings, boolean offset) {
super(settings);
this.offset = offset;
this.setDefaultState(getDefaultState().with(FRAME, false));
}

public BeepBlock(MapColor mapColor, boolean offset) {
this(makeSettings(mapColor), offset);

}

public static Settings makeSettings(MapColor mapColor) {
return DawnBlockSettings.of(Material.STONE, mapColor)
.sounds(BlockSoundGroup.AMETHYST_BLOCK)
.strength(1.5f).requiresTool().item()
.allowsSpawning(BeepBlock::isNotFrame)
.solidBlock(BeepBlock::isNotFrame)
.suffocates(BeepBlock::isNotFrame)
.blockVision(BeepBlock::isNotFrame);
}

private static boolean isFrame(BlockState state) {
return state.get(FRAME);
}

private static boolean isNotFrame(BlockState state, BlockView world, BlockPos pos) {
return !isFrame(state);
}

private static boolean isNotFrame(BlockState state, BlockView world, BlockPos pos, EntityType<?> type) {
return !isFrame(state);
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FRAME);
}

@Override
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) {
return isFrame(state);
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return isFrame(state) ? VoxelShapes.empty() : VoxelShapes.fullCube();
}

@Override
public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
return isFrame(state) ? VoxelShapes.empty() : VoxelShapes.fullCube();
}

@Override
public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
return isFrame(state) ? 1.0F : 0.2f;
}

@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return getStateAtTime(ctx.getWorld());
}

@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
this.refreshState(world, pos);
this.scheduleTick(world, pos, state.getBlock());
}

@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if(!world.isClient()) {
this.refreshState(world, pos);
this.scheduleTick(world, pos, state.getBlock());
}
}

public void refreshState(World world, BlockPos pos) {
world.setBlockState(pos, getStateAtTime(world));
}

public void scheduleTick(World world, BlockPos pos, Block block) {
int cooldown = world.getGameRules().getInt(MubbleGamerules.BEEP_BLOCK_COOLDOWN);
if(cooldown > 0) {
long worldTime = world.getTime();
int delta = (int) (cooldown - worldTime);
world.scheduleBlockTick(pos, block, (delta == 0) ? cooldown : delta % cooldown);
}
}

public BlockState getStateAtTime(World world) {
int cooldown = world.getGameRules().getInt(MubbleGamerules.BEEP_BLOCK_COOLDOWN);
if(cooldown <= 0) return getDefaultState().with(FRAME, this.offset);
long worldTime = world.getTime();
boolean frame = (int) ((worldTime + (this.offset ? cooldown : 0)) % (cooldown * 2)) < cooldown;
return this.getDefaultState().with(FRAME, frame);
}
public static final int DEFAULT_COOLDOWN = SharedConstants.TICKS_PER_SECOND * 4;
public static final BooleanProperty FRAME = BooleanProperty.of("frame");

public final boolean offset;

public BeepBlock(Settings settings, boolean offset) {
super(settings);
this.offset = offset;
this.setDefaultState(getDefaultState().with(FRAME, false));
}

public BeepBlock(MapColor mapColor, boolean offset) {
this(makeSettings(mapColor), offset);

}

public static Settings makeSettings(MapColor mapColor) {
return DawnBlockSettings.create().mapColor(mapColor)
.sounds(BlockSoundGroup.AMETHYST_BLOCK)
.strength(1.5f).requiresTool().item()
.allowsSpawning(BeepBlock::isNotFrame)
.solidBlock(BeepBlock::isNotFrame)
.suffocates(BeepBlock::isNotFrame)
.blockVision(BeepBlock::isNotFrame);
}

private static boolean isFrame(BlockState state) {
return state.get(FRAME);
}

private static boolean isNotFrame(BlockState state, BlockView world, BlockPos pos) {
return !isFrame(state);
}

private static boolean isNotFrame(BlockState state, BlockView world, BlockPos pos, EntityType<?> type) {
return !isFrame(state);
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FRAME);
}

@Override
public boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {
return isFrame(state);
}

@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return isFrame(state) ? VoxelShapes.empty() : VoxelShapes.fullCube();
}

@Override
public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
return isFrame(state) ? VoxelShapes.empty() : VoxelShapes.fullCube();
}

@Override
public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
return isFrame(state) ? 1.0F : 0.2f;
}

@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return getStateAtTime(ctx.getWorld());
}

@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
this.refreshState(world, pos);
this.scheduleTick(world, pos, state.getBlock());
}

@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!world.isClient()) {
this.refreshState(world, pos);
this.scheduleTick(world, pos, state.getBlock());
}
}

public void refreshState(World world, BlockPos pos) {
world.setBlockState(pos, getStateAtTime(world));
}

public void scheduleTick(World world, BlockPos pos, Block block) {
int cooldown = world.getGameRules().getInt(MubbleGamerules.BEEP_BLOCK_COOLDOWN);
if (cooldown > 0) {
long worldTime = world.getTime();
int delta = (int) (cooldown - worldTime);
world.scheduleBlockTick(pos, block, (delta == 0) ? cooldown : delta % cooldown);
}
}

public BlockState getStateAtTime(World world) {
int cooldown = world.getGameRules().getInt(MubbleGamerules.BEEP_BLOCK_COOLDOWN);
if (cooldown <= 0) return getDefaultState().with(FRAME, this.offset);
long worldTime = world.getTime();
boolean frame = (int) ((worldTime + (this.offset ? cooldown : 0)) % (cooldown * 2)) < cooldown;
return this.getDefaultState().with(FRAME, frame);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.hugman.mubble.screen.BumpableBlockScreenHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -18,25 +19,23 @@ public class BumpableBlockScreen extends HandledScreen<BumpableBlockScreenHandle
public BumpableBlockScreen(BumpableBlockScreenHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title);

this.passEvents = false;
this.backgroundHeight = 133;
this.playerInventoryTitleY = this.backgroundHeight - 94;
}

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
super.render(matrices, mouseX, mouseY, delta);
this.drawMouseoverTooltip(matrices, mouseX, mouseY);
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
this.renderBackground(context);
super.render(context, mouseX, mouseY, delta);
this.drawMouseoverTooltip(context, mouseX, mouseY);
}

@Override
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
RenderSystem.setShaderTexture(0, TEXTURE);
int i = (this.width - this.backgroundWidth) / 2;
int j = (this.height - this.backgroundHeight) / 2;
this.drawTexture(matrices, i, j, 0, 0, this.backgroundWidth, this.backgroundHeight);
context.drawTexture(TEXTURE, i, j, 0, 0, this.backgroundWidth, this.backgroundHeight);
}
}
2 changes: 1 addition & 1 deletion src/main/java/fr/hugman/mubble/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class EntityMixin {
@Inject(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setPosition(DDD)V", ordinal = 1))
private void mubble$move(MovementType type, Vec3d movement, CallbackInfo ci) {
Entity thisEntity = (Entity) (Object) this;
World world = thisEntity.world;
World world = thisEntity.getWorld();
Vec3d vec3d = this.adjustMovementForCollisions(movement);
if(vec3d != null && vec3d.getY() > 0) {
Vec3d headPos = thisEntity.getPos().add(0, thisEntity.getHeight(), 0);
Expand Down
53 changes: 32 additions & 21 deletions src/main/java/fr/hugman/mubble/registry/SuperMario.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.hugman.dawn.DawnFactory;
import fr.hugman.dawn.Registrar;
import fr.hugman.dawn.block.DawnBlockSettings;
import fr.hugman.dawn.item.DawnItemSettings;
import fr.hugman.mubble.Mubble;
import fr.hugman.mubble.block.BeepBlock;
import fr.hugman.mubble.block.EmptyBlock;
Expand All @@ -23,7 +24,10 @@
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.resource.featuretoggle.FeatureFlags;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.text.Text;
import net.minecraft.util.Rarity;
Expand All @@ -45,14 +49,17 @@ public class SuperMario {
public static final BeepBlock RED_BEEP_BLOCK = new BeepBlock(MapColor.RED, false);
public static final BeepBlock BLUE_BEEP_BLOCK = new BeepBlock(MapColor.BLUE, true);

public static final ScreenHandlerType<BumpableBlockScreenHandler> BUMPABLE_BLOCK_SCREEN_HANDLER = new ScreenHandlerType<>(BumpableBlockScreenHandler::new);
public static final ScreenHandlerType<BumpableBlockScreenHandler> BUMPABLE_BLOCK_SCREEN_HANDLER = new ScreenHandlerType<>(BumpableBlockScreenHandler::new, FeatureFlags.VANILLA_FEATURES);
public static final BlockEntityType<BumpableBlockEntity> BUMPABLE_BLOCK_ENTITY_TYPE =
FabricBlockEntityTypeBuilder.create(BumpableBlockEntity::new, QUESTION_BLOCK, BRICK_BLOCK, GOLD_BLOCK, NOTE_BLOCK, EXCLAMATION_BLOCK).build();
public static final TagKey<Item> CAN_OPEN_BUMPABLE_BLOCKS = DawnFactory.itemTag(Mubble.id("can_open_bumpable_blocks"));

public static final CapeFeatherItem CAPE_FEATHER = new CapeFeatherItem(new Item.Settings(), false);
public static final CapeFeatherItem SUPER_CAPE_FEATHER = new CapeFeatherItem(new Item.Settings().rarity(Rarity.EPIC), true);

// ITEM GROUP
public static final RegistryKey<ItemGroup> ITEM_GROUP = RegistryKey.of(RegistryKeys.ITEM_GROUP, Mubble.id("super_mario"));

public static void init(Registrar r) {
r.add("maker_glove", MAKER_GLOVE);

Expand All @@ -73,26 +80,30 @@ public static void init(Registrar r) {

r.add("cape_feather", CAPE_FEATHER);
r.add("super_cape_feather", SUPER_CAPE_FEATHER);

appendItemGroups();
}

public static final ItemGroup GROUP = FabricItemGroup.builder(Mubble.id("super_mario"))
.displayName(Text.translatable("item_group.mubble.super_mario"))
.icon(() -> new ItemStack(SuperMario.QUESTION_BLOCK))
.entries((enabledFeatures, entries, operatorEnabled) -> {
entries.add(SuperMario.MAKER_GLOVE);
entries.add(SuperMario.QUESTION_BLOCK);
entries.add(SuperMario.EMPTY_BLOCK);
entries.add(SuperMario.BRICK_BLOCK);
entries.add(SuperMario.GOLD_BLOCK);
entries.add(SuperMario.NOTE_BLOCK);
entries.add(SuperMario.EXCLAMATION_BLOCK);
entries.add(SuperMario.SNAKE_BLOCK);
entries.add(SuperMario.FAST_SNAKE_BLOCK);
entries.add(SuperMario.SLOW_SNAKE_BLOCK);
entries.add(SuperMario.RED_BEEP_BLOCK);
entries.add(SuperMario.BLUE_BEEP_BLOCK);
entries.add(SuperMario.CAPE_FEATHER);
entries.add(SuperMario.SUPER_CAPE_FEATHER);
})
.build();
public static void appendItemGroups() {
Registry.register(Registries.ITEM_GROUP, ITEM_GROUP, FabricItemGroup.builder()
.displayName(Text.translatable("item_group.mubble.super_mario"))
.icon(() -> new ItemStack(SuperMario.QUESTION_BLOCK))
.entries((displayContext, entries) -> {
entries.add(SuperMario.MAKER_GLOVE);
entries.add(SuperMario.QUESTION_BLOCK);
entries.add(SuperMario.EMPTY_BLOCK);
entries.add(SuperMario.BRICK_BLOCK);
entries.add(SuperMario.GOLD_BLOCK);
entries.add(SuperMario.NOTE_BLOCK);
entries.add(SuperMario.EXCLAMATION_BLOCK);
entries.add(SuperMario.SNAKE_BLOCK);
entries.add(SuperMario.FAST_SNAKE_BLOCK);
entries.add(SuperMario.SLOW_SNAKE_BLOCK);
entries.add(SuperMario.RED_BEEP_BLOCK);
entries.add(SuperMario.BLUE_BEEP_BLOCK);
entries.add(SuperMario.CAPE_FEATHER);
entries.add(SuperMario.SUPER_CAPE_FEATHER);
})
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public boolean canUse(PlayerEntity player) {
return this.inventory.canPlayerUse(player);
}


@Override
public void close(PlayerEntity player) {
super.close(player);
public void onClosed(PlayerEntity player) {
super.onClosed(player);
this.inventory.onClose(player);
}
}
Loading

0 comments on commit 3dd6b5b

Please sign in to comment.