mirror of
https://github.com/TeamMidnightDust/VisualOverhaul.git
synced 2025-12-16 14:05:08 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afac024e9e | ||
|
|
f802e803b9 | ||
|
|
0d008e40d9 |
@@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
loader_version=0.11.1
|
loader_version=0.11.1
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 3.0.0
|
mod_version = 3.1.0
|
||||||
maven_group = eu.midnightdust
|
maven_group = eu.midnightdust
|
||||||
archives_base_name = visualoverhaul
|
archives_base_name = visualoverhaul
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package eu.midnightdust.visualoverhaul.block;
|
package eu.midnightdust.visualoverhaul.block;
|
||||||
|
|
||||||
|
import eu.midnightdust.visualoverhaul.VisualOverhaul;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
@@ -12,7 +13,6 @@ import net.minecraft.potion.PotionUtil;
|
|||||||
import net.minecraft.potion.Potions;
|
import net.minecraft.potion.Potions;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.sound.BlockSoundGroup;
|
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.stat.Stats;
|
import net.minecraft.stat.Stats;
|
||||||
@@ -32,6 +32,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class PuddleBlock extends Block {
|
public class PuddleBlock extends Block {
|
||||||
|
|
||||||
protected final FlowableFluid fluid;
|
protected final FlowableFluid fluid;
|
||||||
@@ -121,7 +122,38 @@ public class PuddleBlock extends Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||||
return world.getBlockState(pos.down()).isSideSolidFullSquare(world,pos,Direction.UP);
|
if (world.getBlockState(pos) == Blocks.AIR.getDefaultState() || world.getBlockState(pos) == VisualOverhaul.Puddle.getDefaultState()) {
|
||||||
|
int i;
|
||||||
|
// Check if there are fluids on the sides or corners of the block above
|
||||||
|
for (i = 2; i < 6; ++i) {
|
||||||
|
BlockPos pos1 = pos.up();
|
||||||
|
BlockPos pos2 = pos1.offset(Direction.byId(i));
|
||||||
|
if (!world.getFluidState(pos1.offset(Direction.byId(i))).isEmpty()) {
|
||||||
|
// When sides of the block above have water don't place the puddle
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!world.getFluidState(pos2.offset(Direction.byId(i).rotateYClockwise())).isEmpty()) {
|
||||||
|
// When corners of the block above have water don't place the puddle
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check if there are fluids on the sides or corners of the block below
|
||||||
|
for (i = 2; i < 6; ++i) {
|
||||||
|
BlockPos pos1 = pos.down();
|
||||||
|
BlockPos pos2 = pos1.offset(Direction.byId(i));
|
||||||
|
if (!world.getFluidState(pos1.offset(Direction.byId(i))).isEmpty()) {
|
||||||
|
// When sides of the block below have water don't place the puddle
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!world.getFluidState(pos2.offset(Direction.byId(i).rotateYClockwise())).isEmpty()) {
|
||||||
|
// When corners of the block below have water don't place the puddle
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return world.getBlockState(pos.down()).isSideSolidFullSquare(world, pos, Direction.UP);
|
||||||
|
}
|
||||||
|
// When there's already another block at the position don't place the puddle
|
||||||
|
else return false;
|
||||||
}
|
}
|
||||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
|
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
|
||||||
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
|
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package eu.midnightdust.visualoverhaul.block.renderer;
|
|||||||
|
|
||||||
import eu.midnightdust.visualoverhaul.VisualOverhaulClient;
|
import eu.midnightdust.visualoverhaul.VisualOverhaulClient;
|
||||||
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
import eu.midnightdust.visualoverhaul.config.VOConfig;
|
||||||
|
import eu.midnightdust.visualoverhaul.util.sound.SoundTest;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.entity.JukeboxBlockEntity;
|
import net.minecraft.block.entity.JukeboxBlockEntity;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.render.RenderLayer;
|
import net.minecraft.client.render.RenderLayer;
|
||||||
@@ -16,11 +18,15 @@ import net.minecraft.client.util.math.MatrixStack;
|
|||||||
import net.minecraft.client.util.math.Vector3f;
|
import net.minecraft.client.util.math.Vector3f;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.state.property.Properties;
|
import net.minecraft.state.property.Properties;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
public class JukeboxBlockEntityRenderer extends BlockEntityRenderer<JukeboxBlockEntity> {
|
public class JukeboxBlockEntityRenderer extends BlockEntityRenderer<JukeboxBlockEntity> {
|
||||||
|
private ItemStack record;
|
||||||
|
private Identifier discItem;
|
||||||
|
|
||||||
public JukeboxBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) {
|
public JukeboxBlockEntityRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher) {
|
||||||
super(blockEntityRenderDispatcher);
|
super(blockEntityRenderDispatcher);
|
||||||
@@ -31,7 +37,26 @@ public class JukeboxBlockEntityRenderer extends BlockEntityRenderer<JukeboxBlock
|
|||||||
|
|
||||||
if (VOConfig.jukebox) {
|
if (VOConfig.jukebox) {
|
||||||
int lightAbove = WorldRenderer.getLightmapCoordinates(blockEntity.getWorld(), blockEntity.getPos().up());
|
int lightAbove = WorldRenderer.getLightmapCoordinates(blockEntity.getWorld(), blockEntity.getPos().up());
|
||||||
ItemStack record = blockEntity.getRecord();
|
|
||||||
|
// Gets the record sound played at the position of the jukebox //
|
||||||
|
if (SoundTest.getSound(blockEntity.getPos()) != null) {
|
||||||
|
// Converts the Sound Id to the item id of the approprieate disc (minecraft:music_disc.cat -> minecraft:music_disc_cat) //
|
||||||
|
discItem = new Identifier(String.valueOf(SoundTest.getSound(blockEntity.getPos())).replace(".", "_"));
|
||||||
|
}
|
||||||
|
// If the sound is stopped or no sound is playing, the stack is set to an empty stack //
|
||||||
|
if (SoundTest.getSound(blockEntity.getPos()) == null) {
|
||||||
|
discItem = null;
|
||||||
|
record = ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
// Tries to get the disc item from the registry //
|
||||||
|
else if (Registry.ITEM.getOrEmpty(discItem).isPresent()) {
|
||||||
|
record = new ItemStack(Registry.ITEM.get(discItem));
|
||||||
|
}
|
||||||
|
// Fallback to serverside implementation if the id doesn't match an item //
|
||||||
|
else {
|
||||||
|
record = blockEntity.getRecord();
|
||||||
|
}
|
||||||
|
|
||||||
record.setCount(2);
|
record.setCount(2);
|
||||||
|
|
||||||
matrices.push();
|
matrices.push();
|
||||||
@@ -42,7 +67,7 @@ public class JukeboxBlockEntityRenderer extends BlockEntityRenderer<JukeboxBlock
|
|||||||
MinecraftClient.getInstance().getItemRenderer().renderItem(record, ModelTransformation.Mode.GROUND, lightAbove, overlay, matrices, vertexConsumers);
|
MinecraftClient.getInstance().getItemRenderer().renderItem(record, ModelTransformation.Mode.GROUND, lightAbove, overlay, matrices, vertexConsumers);
|
||||||
|
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
if (VOConfig.jukebox_fake_block) {
|
if (VOConfig.jukebox_fake_block && blockEntity.getWorld().getBlockState(blockEntity.getPos().up()).getBlock() == Blocks.AIR) {
|
||||||
matrices.push();
|
matrices.push();
|
||||||
matrices.translate(0f, 1f, 0f);
|
matrices.translate(0f, 1f, 0f);
|
||||||
if (record == ItemStack.EMPTY) {
|
if (record == ItemStack.EMPTY) {
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package eu.midnightdust.visualoverhaul.mixin;
|
||||||
|
|
||||||
|
import eu.midnightdust.visualoverhaul.util.sound.SoundTest;
|
||||||
|
import net.minecraft.client.sound.SoundInstance;
|
||||||
|
import net.minecraft.client.sound.SoundSystem;
|
||||||
|
import net.minecraft.sound.SoundCategory;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(SoundSystem.class)
|
||||||
|
public abstract class MixinSoundSystem {
|
||||||
|
|
||||||
|
@Shadow private boolean started;
|
||||||
|
|
||||||
|
private BlockPos jukeboxPos;
|
||||||
|
|
||||||
|
@Inject(at = @At("TAIL"),method = "play(Lnet/minecraft/client/sound/SoundInstance;)V")
|
||||||
|
public void onPlayRecordSound(SoundInstance soundInstance, CallbackInfo ci) {
|
||||||
|
if (soundInstance.getCategory().equals(SoundCategory.RECORDS) && this.started) {
|
||||||
|
jukeboxPos = new BlockPos(soundInstance.getX(),soundInstance.getY(),soundInstance.getZ());
|
||||||
|
SoundTest.soundPos.put(jukeboxPos, soundInstance.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(at = @At("TAIL"),method = "stop(Lnet/minecraft/client/sound/SoundInstance;)V")
|
||||||
|
public void onStopRecordSound(SoundInstance soundInstance, CallbackInfo ci) {
|
||||||
|
if (soundInstance.getCategory().equals(SoundCategory.RECORDS) && SoundTest.soundPos.containsKey(new BlockPos(soundInstance.getX(),soundInstance.getY(),soundInstance.getZ()))) {
|
||||||
|
jukeboxPos = new BlockPos(soundInstance.getX(),soundInstance.getY(),soundInstance.getZ());
|
||||||
|
SoundTest.soundPos.remove(jukeboxPos,soundInstance.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package eu.midnightdust.visualoverhaul.util.sound;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SoundTest {
|
||||||
|
|
||||||
|
public static Map<BlockPos, Identifier> soundPos = Maps.newHashMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Sound provided in MixinSoundSystem
|
||||||
|
* {@link eu.midnightdust.visualoverhaul.mixin.MixinSoundSystem}
|
||||||
|
*/
|
||||||
|
public static Identifier getSound(BlockPos pos) {
|
||||||
|
if (soundPos.containsKey(pos)) {
|
||||||
|
return soundPos.get(pos);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,9 @@
|
|||||||
"MixinAbstractFurnaceBlockEntity",
|
"MixinAbstractFurnaceBlockEntity",
|
||||||
"MixinServerWorld"
|
"MixinServerWorld"
|
||||||
],
|
],
|
||||||
|
"client": [
|
||||||
|
"MixinSoundSystem"
|
||||||
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user